Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

SQL Server Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(SQL Server) Shippo Adding Metadata

Demonstrates how to add metadata to the tracking request through a POST request.

For more information, see https://goshippo.com/docs/tracking/

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Implements the following CURL command:

    -- curl https://api.goshippo.com/tracks/ \
    --     -H "Authorization: ShippoToken <API_TOKEN>" \
    --     -d carrier="shippo" \
    --     -d tracking_number="SHIPPO_TRANSIT" \
    --     -d metadata="Order 000123"

    DECLARE @req int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.HttpRequest', @req OUT

    EXEC sp_OASetProperty @req, 'HttpVerb', 'POST'
    EXEC sp_OASetProperty @req, 'Path', '/tracks/'
    EXEC sp_OASetProperty @req, 'ContentType', 'application/x-www-form-urlencoded'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'carrier', 'shippo'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'tracking_number', 'SHIPPO_TRANSIT'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'metadata', 'Order 000123'

    EXEC sp_OAMethod @req, 'AddHeader', NULL, 'Authorization', 'ShippoToken <API_TOKEN>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostUrlEncoded', @resp OUT, 'https://api.goshippo.com/tracks/', @req
    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 @req
        RETURN
      END

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

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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 @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @req
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    -- {
    --   "messages": [
    --   ],
    --   "carrier": "shippo",
    --   "tracking_number": "SHIPPO_TRANSIT",
    --   "address_from": {
    --     "city": "San Francisco",
    --     "state": "CA",
    --     "zip": "94103",
    --     "country": "US"
    --   },
    --   "address_to": {
    --     "city": "Chicago",
    --     "state": "IL",
    --     "zip": "60611",
    --     "country": "US"
    --   },
    --   "eta": "2019-07-07T17:07:44.989Z",
    --   "original_eta": "2019-07-07T17:07:44.989Z",
    --   "servicelevel": {
    --     "token": "shippo_priority",
    --     "name": "Priority Mail"
    --   },
    --   "metadata": "Shippo test tracking",
    --   "tracking_status": {
    --     "object_created": "2019-07-04T17:07:45.003Z",
    --     "object_updated": null,
    --     "object_id": "ee35fb56f5d04021b36168abedc04573",
    --     "status": "TRANSIT",
    --     "status_details": "Your shipment has departed from the origin.",
    --     "status_date": "2019-07-03T15:02:45.003Z",
    --     "substatus": null,
    --     "location": {
    --       "city": "San Francisco",
    --       "state": "CA",
    --       "zip": "94103",
    --       "country": "US"
    --     }
    --   },
    --   "tracking_history": [
    --     {
    --       "object_created": "2019-07-04T17:07:45.005Z",
    --       "object_updated": null,
    --       "object_id": "2121a59f53ed42e0ae0436f636179156",
    --       "status": "UNKNOWN",
    --       "status_details": "The carrier has received the electronic shipment information.",
    --       "status_date": "2019-07-02T12:57:45.005Z",
    --       "substatus": null,
    --       "location": {
    --         "city": "San Francisco",
    --         "state": "CA",
    --         "zip": "94103",
    --         "country": "US"
    --       }
    --     },
    --     {
    --       "object_created": "2019-07-04T17:07:45.005Z",
    --       "object_updated": null,
    --       "object_id": "06f949db1a8245beaa28df264b368a76",
    --       "status": "TRANSIT",
    --       "status_details": "Your shipment has departed from the origin.",
    --       "status_date": "2019-07-03T15:02:45.005Z",
    --       "substatus": null,
    --       "location": {
    --         "city": "San Francisco",
    --         "state": "CA",
    --         "zip": "94103",
    --         "country": "US"
    --       }
    --     }
    --   ],
    --   "transaction": null,
    --   "test": true
    -- }

    -- 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 @object_created nvarchar(4000)

    DECLARE @object_updated nvarchar(4000)

    DECLARE @object_id nvarchar(4000)

    DECLARE @status nvarchar(4000)

    DECLARE @status_details nvarchar(4000)

    DECLARE @status_date nvarchar(4000)

    DECLARE @substatus nvarchar(4000)

    DECLARE @locationCity nvarchar(4000)

    DECLARE @locationState nvarchar(4000)

    DECLARE @locationZip nvarchar(4000)

    DECLARE @locationCountry nvarchar(4000)

    DECLARE @carrier nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @carrier OUT, 'carrier'
    DECLARE @tracking_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_number OUT, 'tracking_number'
    DECLARE @address_fromCity nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_fromCity OUT, 'address_from.city'
    DECLARE @address_fromState nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_fromState OUT, 'address_from.state'
    DECLARE @address_fromZip nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_fromZip OUT, 'address_from.zip'
    DECLARE @address_fromCountry nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_fromCountry OUT, 'address_from.country'
    DECLARE @address_toCity nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_toCity OUT, 'address_to.city'
    DECLARE @address_toState nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_toState OUT, 'address_to.state'
    DECLARE @address_toZip nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_toZip OUT, 'address_to.zip'
    DECLARE @address_toCountry nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @address_toCountry OUT, 'address_to.country'
    DECLARE @eta nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @eta OUT, 'eta'
    DECLARE @original_eta nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @original_eta OUT, 'original_eta'
    DECLARE @servicelevelToken nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @servicelevelToken OUT, 'servicelevel.token'
    DECLARE @servicelevelName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @servicelevelName OUT, 'servicelevel.name'
    DECLARE @metadata nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadata OUT, 'metadata'
    DECLARE @tracking_statusObject_created nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusObject_created OUT, 'tracking_status.object_created'
    DECLARE @tracking_statusObject_updated nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusObject_updated OUT, 'tracking_status.object_updated'
    DECLARE @tracking_statusObject_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusObject_id OUT, 'tracking_status.object_id'
    DECLARE @tracking_statusStatus nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusStatus OUT, 'tracking_status.status'
    DECLARE @tracking_statusStatus_details nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusStatus_details OUT, 'tracking_status.status_details'
    DECLARE @tracking_statusStatus_date nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusStatus_date OUT, 'tracking_status.status_date'
    DECLARE @tracking_statusSubstatus nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusSubstatus OUT, 'tracking_status.substatus'
    DECLARE @tracking_statusLocationCity nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusLocationCity OUT, 'tracking_status.location.city'
    DECLARE @tracking_statusLocationState nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusLocationState OUT, 'tracking_status.location.state'
    DECLARE @tracking_statusLocationZip nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusLocationZip OUT, 'tracking_status.location.zip'
    DECLARE @tracking_statusLocationCountry nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @tracking_statusLocationCountry OUT, 'tracking_status.location.country'
    DECLARE @transaction nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @transaction OUT, 'transaction'
    DECLARE @test int
    EXEC sp_OAMethod @jResp, 'BoolOf', @test OUT, 'test'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'messages'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'tracking_history'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @object_created OUT, 'tracking_history[i].object_created'
        EXEC sp_OAMethod @jResp, 'StringOf', @object_updated OUT, 'tracking_history[i].object_updated'
        EXEC sp_OAMethod @jResp, 'StringOf', @object_id OUT, 'tracking_history[i].object_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'tracking_history[i].status'
        EXEC sp_OAMethod @jResp, 'StringOf', @status_details OUT, 'tracking_history[i].status_details'
        EXEC sp_OAMethod @jResp, 'StringOf', @status_date OUT, 'tracking_history[i].status_date'
        EXEC sp_OAMethod @jResp, 'StringOf', @substatus OUT, 'tracking_history[i].substatus'
        EXEC sp_OAMethod @jResp, 'StringOf', @locationCity OUT, 'tracking_history[i].location.city'
        EXEC sp_OAMethod @jResp, 'StringOf', @locationState OUT, 'tracking_history[i].location.state'
        EXEC sp_OAMethod @jResp, 'StringOf', @locationZip OUT, 'tracking_history[i].location.zip'
        EXEC sp_OAMethod @jResp, 'StringOf', @locationCountry OUT, 'tracking_history[i].location.country'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @req
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.