Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

SQL Server Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois
Mastercard

MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(SQL Server) Shippo Create a Batch

Demonstrates how to create and purchase up to 10,000 shipments in a single API request.

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- 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.

    -- {
    --   "default_carrier_account": "078870331023437cb917f5187429b093",
    --   "default_servicelevel_token": "usps_priority",
    --   "label_filetype": "PDF_4x6",
    --   "metadata": "BATCH #170",
    --   "batch_shipments": [
    --     {
    --       "shipment": {
    --         "address_from": {
    --           "name": "Mr Hippo",
    --           "street1": "965 Mission St",
    --           "street2": "Ste 201",
    --           "city": "San Francisco",
    --           "state": "CA",
    --           "zip": "94103",
    --           "country": "US",
    --           "phone": "4151234567",
    --           "email": "mrhippo@goshippo.com"
    --         },
    --         "address_to": {
    --           "name": "Mrs Hippo",
    --           "company": "",
    --           "street1": "Broadway 1",
    --           "street2": "",
    --           "city": "New York",
    --           "state": "NY",
    --           "zip": "10007",
    --           "country": "US",
    --           "phone": "4151234567",
    --           "email": "mrshippo@goshippo.com"
    --         },
    --         "parcels": [
    --           {
    --             "length": "5",
    --             "width": "5",
    --             "height": "5",
    --             "distance_unit": "in",
    --             "weight": "2",
    --             "mass_unit": "oz"
    --           }
    --         ]
    --       }
    --     },
    --     {
    --       "shipment": {
    --         "address_from": {
    --           "name": "Mr Hippo",
    --           "street1": "1092 Indian Summer Ct",
    --           "city": "San Jose",
    --           "state": "CA",
    --           "zip": "95122",
    --           "country": "US",
    --           "phone": "4151234567",
    --           "email": "mrhippo@goshippo.com"
    --         },
    --         "address_to": {
    --           "name": "Mrs Hippo",
    --           "company": "",
    --           "street1": "Broadway 1",
    --           "street2": "",
    --           "city": "New York",
    --           "state": "NY",
    --           "zip": "10007",
    --           "country": "US",
    --           "phone": "4151234567",
    --           "email": "mrshippo@goshippo.com"
    --         },
    --         "parcels": [
    --           {
    --             "length": "5",
    --             "width": "5",
    --             "height": "5",
    --             "distance_unit": "in",
    --             "weight": "20",
    --             "mass_unit": "lb"
    --           }
    --         ]
    --       },
    --       "carrier_account": "a4391cd4ab974f478f55dc08b5c8e3b3",
    --       "servicelevel_token": "fedex_2_day"
    --     }
    --   ]
    -- }

    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, 'default_carrier_account', '078870331023437cb917f5187429b093'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'default_servicelevel_token', 'usps_priority'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'label_filetype', 'PDF_4x6'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'metadata', 'BATCH #170'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.name', 'Mr Hippo'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.street1', '965 Mission St'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.street2', 'Ste 201'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.city', 'San Francisco'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.state', 'CA'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.zip', '94103'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.country', 'US'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.phone', '4151234567'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_from.email', 'mrhippo@goshippo.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.name', 'Mrs Hippo'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.company', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.street1', 'Broadway 1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.street2', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.city', 'New York'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.state', 'NY'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.zip', '10007'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.country', 'US'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.phone', '4151234567'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.address_to.email', 'mrshippo@goshippo.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.parcels[0].length', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.parcels[0].width', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.parcels[0].height', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.parcels[0].distance_unit', 'in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.parcels[0].weight', '2'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[0].shipment.parcels[0].mass_unit', 'oz'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.name', 'Mr Hippo'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.street1', '1092 Indian Summer Ct'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.city', 'San Jose'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.state', 'CA'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.zip', '95122'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.country', 'US'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.phone', '4151234567'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_from.email', 'mrhippo@goshippo.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.name', 'Mrs Hippo'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.company', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.street1', 'Broadway 1'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.street2', ''
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.city', 'New York'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.state', 'NY'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.zip', '10007'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.country', 'US'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.phone', '4151234567'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.address_to.email', 'mrshippo@goshippo.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.parcels[0].length', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.parcels[0].width', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.parcels[0].height', '5'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.parcels[0].distance_unit', 'in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.parcels[0].weight', '20'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].shipment.parcels[0].mass_unit', 'lb'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].carrier_account', 'a4391cd4ab974f478f55dc08b5c8e3b3'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'batch_shipments[1].servicelevel_token', 'fedex_2_day'

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

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.goshippo.com/batches/', '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 @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    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 @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        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)

    -- {
    --   "object_id": "a015eb693cca465dbb6523ce6d2e3c65",
    --   "object_owner": "admin",
    --   "status": "VALIDATING",
    --   "object_created": "2016-09-12T15:25:43.465Z",
    --   "object_updated": "2016-09-12T15:25:43.465Z",
    --   "metadata": "BATCH #170",
    --   "default_carrier_account": "078870331023437cb917f5187429b093",
    --   "default_servicelevel_token": "usps_priority",
    --   "label_filetype": "PDF_4x6",
    --   "batch_shipments": {
    --     "next": null,
    --     "previous": null,
    --     "results": [
    --     ]
    --   },
    --   "object_results": {
    --     "purchase_succeeded": 0,
    --     "purchase_failed": 0,
    --     "creation_failed": 0,
    --     "creation_succeeded": 0
    --   },
    --   "label_url": [
    --   ]
    -- }

    -- 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_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 @status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'status'
    DECLARE @object_created nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @object_created OUT, 'object_created'
    DECLARE @object_updated nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @object_updated OUT, 'object_updated'
    DECLARE @metadata nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @metadata OUT, 'metadata'
    DECLARE @default_carrier_account nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @default_carrier_account OUT, 'default_carrier_account'
    DECLARE @default_servicelevel_token nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @default_servicelevel_token OUT, 'default_servicelevel_token'
    DECLARE @label_filetype nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @label_filetype OUT, 'label_filetype'
    DECLARE @batch_shipmentsNext nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @batch_shipmentsNext OUT, 'batch_shipments.next'
    DECLARE @batch_shipmentsPrevious nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @batch_shipmentsPrevious OUT, 'batch_shipments.previous'
    DECLARE @object_resultsPurchase_succeeded int
    EXEC sp_OAMethod @jResp, 'IntOf', @object_resultsPurchase_succeeded OUT, 'object_results.purchase_succeeded'
    DECLARE @object_resultsPurchase_failed int
    EXEC sp_OAMethod @jResp, 'IntOf', @object_resultsPurchase_failed OUT, 'object_results.purchase_failed'
    DECLARE @object_resultsCreation_failed int
    EXEC sp_OAMethod @jResp, 'IntOf', @object_resultsCreation_failed OUT, 'object_results.creation_failed'
    DECLARE @object_resultsCreation_succeeded int
    EXEC sp_OAMethod @jResp, 'IntOf', @object_resultsCreation_succeeded OUT, 'object_results.creation_succeeded'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'batch_shipments.results'
    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, 'label_url'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        SELECT @i = @i + 1
      END

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


END
GO

 

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