Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "carrier_ids": [
-- "{{stamps_com}}",
-- "{{fedex}}",
-- "{{ups}}"
-- ],
-- "from_country_code": "US",
-- "from_postal_code": "78756",
-- "to_country_code": "US",
-- "to_postal_code": "91521",
-- "weight": {
-- "value": 17,
-- "unit": "pound"
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'carrier_ids[0]', '{{stamps_com}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'carrier_ids[1]', '{{fedex}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'carrier_ids[2]', '{{ups}}'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'from_country_code', 'US'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'from_postal_code', '78756'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_country_code', 'US'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_postal_code', '91521'
EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'weight.value', 17
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'weight.unit', 'pound'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'API-Key', '{{API_KEY}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.shipengine.com/v1/rates/estimate', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jarrResp int
-- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jarrResp OUT
EXEC sp_OAMethod @jarrResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jarrResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jarrResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jarrResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- [
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 11.07
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "package",
-- "delivery_days": 7,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-24T00:00:00Z",
-- "carrier_delivery_days": "6",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Media Mail",
-- "service_code": "usps_media_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 38.98
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "package",
-- "delivery_days": 7,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-24T00:00:00Z",
-- "carrier_delivery_days": "6",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Parcel Select Ground",
-- "service_code": "usps_parcel_select",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 39.23
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "package",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 12.72
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "medium_flat_rate_box",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 6.98
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "small_flat_rate_box",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 17.47
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "large_flat_rate_box",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 6.48
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "flat_rate_envelope",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 7.03
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "flat_rate_padded_envelope",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 16.1
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "regional_rate_box_b",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 6.78
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "flat_rate_legal_envelope",
-- "delivery_days": 3,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-20T00:00:00Z",
-- "carrier_delivery_days": "3",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail",
-- "service_code": "usps_priority_mail",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 103.04
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "package",
-- "delivery_days": 2,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-19T00:00:00Z",
-- "carrier_delivery_days": "1-2",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail Express",
-- "service_code": "usps_priority_mail_express",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 22.68
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "flat_rate_envelope",
-- "delivery_days": 2,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-19T00:00:00Z",
-- "carrier_delivery_days": "1-2",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail Express",
-- "service_code": "usps_priority_mail_express",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 23.18
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "flat_rate_padded_envelope",
-- "delivery_days": 2,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-19T00:00:00Z",
-- "carrier_delivery_days": "1-2",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail Express",
-- "service_code": "usps_priority_mail_express",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- },
-- {
-- "rate_type": "check",
-- "carrier_id": "se-121861",
-- "shipping_amount": {
-- "currency": "usd",
-- "amount": 22.8
-- },
-- "insurance_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "confirmation_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "other_amount": {
-- "currency": "usd",
-- "amount": 0
-- },
-- "zone": 6,
-- "package_type": "flat_rate_legal_envelope",
-- "delivery_days": 2,
-- "guaranteed_service": false,
-- "estimated_delivery_date": "2019-09-19T00:00:00Z",
-- "carrier_delivery_days": "1-2",
-- "ship_date": "2019-09-17T00:00:00Z",
-- "negotiated_rate": false,
-- "service_type": "USPS Priority Mail Express",
-- "service_code": "usps_priority_mail_express",
-- "trackable": true,
-- "carrier_code": "stamps_com",
-- "carrier_nickname": "ShipEngine Test Account - Stamps.com",
-- "carrier_friendly_name": "Stamps.com",
-- "validation_status": "unknown",
-- "warning_messages": [
-- ],
-- "error_messages": [
-- ]
-- }
-- ]
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @json int
DECLARE @rate_type nvarchar(4000)
DECLARE @carrier_id nvarchar(4000)
DECLARE @v_Currency nvarchar(4000)
DECLARE @Amount nvarchar(4000)
DECLARE @insurance_amountCurrency nvarchar(4000)
DECLARE @insurance_amountAmount int
DECLARE @confirmation_amountCurrency nvarchar(4000)
DECLARE @confirmation_amountAmount int
DECLARE @other_amountCurrency nvarchar(4000)
DECLARE @other_amountAmount int
DECLARE @zone int
DECLARE @package_type nvarchar(4000)
DECLARE @delivery_days int
DECLARE @guaranteed_service int
DECLARE @estimated_delivery_date nvarchar(4000)
DECLARE @carrier_delivery_days nvarchar(4000)
DECLARE @ship_date nvarchar(4000)
DECLARE @negotiated_rate int
DECLARE @service_type nvarchar(4000)
DECLARE @service_code nvarchar(4000)
DECLARE @trackable int
DECLARE @carrier_code nvarchar(4000)
DECLARE @carrier_nickname nvarchar(4000)
DECLARE @carrier_friendly_name nvarchar(4000)
DECLARE @validation_status nvarchar(4000)
DECLARE @j int
DECLARE @count_j int
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAGetProperty @jarrResp, 'Size', @count_i OUT
WHILE @i < @count_i
BEGIN
EXEC sp_OAMethod @jarrResp, 'ObjectAt', @json OUT, @i
EXEC sp_OAMethod @json, 'StringOf', @rate_type OUT, 'rate_type'
EXEC sp_OAMethod @json, 'StringOf', @carrier_id OUT, 'carrier_id'
EXEC sp_OAMethod @json, 'StringOf', @v_Currency OUT, 'shipping_amount.currency'
EXEC sp_OAMethod @json, 'StringOf', @Amount OUT, 'shipping_amount.amount'
EXEC sp_OAMethod @json, 'StringOf', @insurance_amountCurrency OUT, 'insurance_amount.currency'
EXEC sp_OAMethod @json, 'IntOf', @insurance_amountAmount OUT, 'insurance_amount.amount'
EXEC sp_OAMethod @json, 'StringOf', @confirmation_amountCurrency OUT, 'confirmation_amount.currency'
EXEC sp_OAMethod @json, 'IntOf', @confirmation_amountAmount OUT, 'confirmation_amount.amount'
EXEC sp_OAMethod @json, 'StringOf', @other_amountCurrency OUT, 'other_amount.currency'
EXEC sp_OAMethod @json, 'IntOf', @other_amountAmount OUT, 'other_amount.amount'
EXEC sp_OAMethod @json, 'IntOf', @zone OUT, 'zone'
EXEC sp_OAMethod @json, 'StringOf', @package_type OUT, 'package_type'
EXEC sp_OAMethod @json, 'IntOf', @delivery_days OUT, 'delivery_days'
EXEC sp_OAMethod @json, 'BoolOf', @guaranteed_service OUT, 'guaranteed_service'
EXEC sp_OAMethod @json, 'StringOf', @estimated_delivery_date OUT, 'estimated_delivery_date'
EXEC sp_OAMethod @json, 'StringOf', @carrier_delivery_days OUT, 'carrier_delivery_days'
EXEC sp_OAMethod @json, 'StringOf', @ship_date OUT, 'ship_date'
EXEC sp_OAMethod @json, 'BoolOf', @negotiated_rate OUT, 'negotiated_rate'
EXEC sp_OAMethod @json, 'StringOf', @service_type OUT, 'service_type'
EXEC sp_OAMethod @json, 'StringOf', @service_code OUT, 'service_code'
EXEC sp_OAMethod @json, 'BoolOf', @trackable OUT, 'trackable'
EXEC sp_OAMethod @json, 'StringOf', @carrier_code OUT, 'carrier_code'
EXEC sp_OAMethod @json, 'StringOf', @carrier_nickname OUT, 'carrier_nickname'
EXEC sp_OAMethod @json, 'StringOf', @carrier_friendly_name OUT, 'carrier_friendly_name'
EXEC sp_OAMethod @json, 'StringOf', @validation_status OUT, 'validation_status'
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'warning_messages'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @json, 'J', @j
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'error_messages'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @json, 'J', @j
SELECT @j = @j + 1
END
EXEC @hr = sp_OADestroy @json
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jarrResp
END
GO
Curl Command
curl -X POST
-H "API-Key: {{API_KEY}}"
-H "Content-Type: application/json"
-d '{
"carrier_ids": [
"{{stamps_com}}",
"{{fedex}}",
"{{ups}}"
],
"from_country_code": "US",
"from_postal_code": "78756",
"to_country_code": "US",
"to_postal_code": "91521",
"weight": {
"value": 17,
"unit": "pound"
}
}'
https://api.shipengine.com/v1/rates/estimate
Postman Collection Item JSON
{
"name": "Get rate estimates (minimal)",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"carrier_ids\": [\n\t\t\"{{stamps_com}}\",\n\t\t\"{{fedex}}\",\n\t\t\"{{ups}}\"\n\t],\n\t\"from_country_code\": \"US\",\n\t\"from_postal_code\": \"78756\",\n\t\"to_country_code\": \"US\",\n\t\"to_postal_code\": \"91521\",\n\t\"weight\": {\n\t\t\"value\": 17,\n\t\t\"unit\": \"pound\"\n\t}\n}"
},
"url": {
"raw": "https://api.shipengine.com/v1/rates/estimate",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"rates",
"estimate"
]
},
"description": "This request shows you how to get rate estimates when you don't know the full delivery address yet."
},
"response": [
{
"name": "Get rate estimates (minimal)",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"carrier_id\": \"{{stamps_com}}\",\n\t\"from_country_code\": \"US\",\n\t\"from_postal_code\": \"78756\",\n\t\"to_country_code\": \"US\",\n\t\"to_postal_code\": \"91521\",\n\t\"weight\": {\n\t\t\"value\": 17,\n\t\t\"unit\": \"pound\"\n\t}\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.shipengine.com/v1/rates/estimate",
"protocol": "https",
"host": [
"api",
"shipengine",
"com"
],
"path": [
"v1",
"rates",
"estimate"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Tue, 17 Sep 2019 17:48:57 GMT"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Content-Length",
"value": "14422"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Access-Control-Allow-Origin",
"value": "https://www.shipengine.com"
},
{
"key": "Vary",
"value": "Origin"
},
{
"key": "x-shipengine-requestid",
"value": "a0122561-502b-4e6e-93d1-f1498bf6a0b3"
}
],
"cookie": [
],
"body": "[\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 11.07\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"package\",\n \"delivery_days\": 7,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-24T00:00:00Z\",\n \"carrier_delivery_days\": \"6\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Media Mail\",\n \"service_code\": \"usps_media_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 38.98\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"package\",\n \"delivery_days\": 7,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-24T00:00:00Z\",\n \"carrier_delivery_days\": \"6\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Parcel Select Ground\",\n \"service_code\": \"usps_parcel_select\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 39.23\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"package\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 12.72\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"medium_flat_rate_box\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 6.98\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"small_flat_rate_box\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 17.47\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"large_flat_rate_box\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 6.48\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"flat_rate_envelope\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 7.03\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"flat_rate_padded_envelope\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 16.1\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"regional_rate_box_b\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 6.78\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"flat_rate_legal_envelope\",\n \"delivery_days\": 3,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-20T00:00:00Z\",\n \"carrier_delivery_days\": \"3\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail\",\n \"service_code\": \"usps_priority_mail\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 103.04\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"package\",\n \"delivery_days\": 2,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-19T00:00:00Z\",\n \"carrier_delivery_days\": \"1-2\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail Express\",\n \"service_code\": \"usps_priority_mail_express\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 22.68\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"flat_rate_envelope\",\n \"delivery_days\": 2,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-19T00:00:00Z\",\n \"carrier_delivery_days\": \"1-2\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail Express\",\n \"service_code\": \"usps_priority_mail_express\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 23.18\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"flat_rate_padded_envelope\",\n \"delivery_days\": 2,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-19T00:00:00Z\",\n \"carrier_delivery_days\": \"1-2\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail Express\",\n \"service_code\": \"usps_priority_mail_express\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n },\n {\n \"rate_type\": \"check\",\n \"carrier_id\": \"se-121861\",\n \"shipping_amount\": {\n \"currency\": \"usd\",\n \"amount\": 22.8\n },\n \"insurance_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"confirmation_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"other_amount\": {\n \"currency\": \"usd\",\n \"amount\": 0\n },\n \"zone\": 6,\n \"package_type\": \"flat_rate_legal_envelope\",\n \"delivery_days\": 2,\n \"guaranteed_service\": false,\n \"estimated_delivery_date\": \"2019-09-19T00:00:00Z\",\n \"carrier_delivery_days\": \"1-2\",\n \"ship_date\": \"2019-09-17T00:00:00Z\",\n \"negotiated_rate\": false,\n \"service_type\": \"USPS Priority Mail Express\",\n \"service_code\": \"usps_priority_mail_express\",\n \"trackable\": true,\n \"carrier_code\": \"stamps_com\",\n \"carrier_nickname\": \"ShipEngine Test Account - Stamps.com\",\n \"carrier_friendly_name\": \"Stamps.com\",\n \"validation_status\": \"unknown\",\n \"warning_messages\": [],\n \"error_messages\": []\n }\n]"
}
]
}