Sample code for 30+ languages & platforms
SQL Server

Shippo Create a New Manifest

See more Shippo Examples

Demonstrates how to create a manifest for your shipments.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Implements the following CURL command:

    -- curl https://api.goshippo.com/manifests/
    --     -H "Authorization: ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b" \
    --     -H "Content-Type: application/json"  \
    --     -d '{
    --           "carrier_account": "b741b99f95e841639b54272834bc478c",
    --           "shipment_date": "2014-05-16T23:59:59Z",
    --           "address_from": "28828839a2b04e208ac2aa4945fbca9a",
    --           "transactions": [
    --             "64bba01845ef40d29374032599f22588", 
    --             "c169aa586a844cc49da00d0272b590e1"
    --             ],
    --           "async": false
    --         }'

    -- 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_account": "b741b99f95e841639b54272834bc478c",
    --   "shipment_date": "2014-05-16T23:59:59Z",
    --   "address_from": "28828839a2b04e208ac2aa4945fbca9a",
    --   "transactions": [
    --     "64bba01845ef40d29374032599f22588",
    --     "c169aa586a844cc49da00d0272b590e1"
    --   ],
    --   "async": false
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'carrier_account', 'b741b99f95e841639b54272834bc478c'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'shipment_date', '2014-05-16T23:59:59Z'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'address_from', '28828839a2b04e208ac2aa4945fbca9a'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactions[0]', '64bba01845ef40d29374032599f22588'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'transactions[1]', 'c169aa586a844cc49da00d0272b590e1'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'async', 0

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', 'ShippoToken shippo_test_831a7a042784f523b95db65444e6e084b636764b'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT

    EXEC sp_OAMethod @http, 'HttpJson', @success OUT, 'POST', 'https://api.goshippo.com/manifests/', @json, 'application/json', @resp
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, '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 @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @resp
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "address_from": "28828839a2b04e208ac2aa4945fbca9a",
    --   "carrier_account": "b741b99f95e841639b54272834bc478c",
    --   "documents": [
    --     "https://shippo-delivery.s3.amazonaws.com/0fadebf6f60c4aca95fa01bcc59c79ae.pdf?Signature=tlQU3RECwdHUQJQadwqg5bAzGFQ%3D&Expires=1402803835&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA"
    --   ],
    --   "object_created": "2014-05-16T03:43:52.765Z",
    --   "object_id": "0fadebf6f60c4aca95fa01bcc59c79ae",
    --   "object_owner": "mrhippo@goshippo.com",
    --   "object_updated": "2014-05-16T03:43:55.445Z",
    --   "shipment_date": "2014-05-16T23:59:59Z",
    --   "status": "SUCCESS",
    --   "transactions": [
    --     "64bba01845ef40d29374032599f22588",
    --     "c169aa586a844cc49da00d0272b590e1"
    --   ]
    -- }

    -- Sample code for parsing the JSON response...
    -- Use the following online tool to generate parsing code from sample JSON:
    -- Generate Parsing Code from JSON

    DECLARE @strVal nvarchar(4000)

    DECLARE @address_from nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_from OUT, 'address_from'
    DECLARE @carrier_account nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @carrier_account OUT, 'carrier_account'
    DECLARE @object_created nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @object_created OUT, 'object_created'
    DECLARE @object_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @object_id OUT, 'object_id'
    DECLARE @object_owner nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @object_owner OUT, 'object_owner'
    DECLARE @object_updated nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @object_updated OUT, 'object_updated'
    DECLARE @shipment_date nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @shipment_date OUT, 'shipment_date'
    DECLARE @status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'documents'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'documents[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'transactions'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'transactions[i]'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @resp
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO