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

DataFlex 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
JCC Cyprus
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

 

 

 

(DataFlex) Amazon SP-API Get Specific Order

See more Amazon SP-API Examples

Get a specific Amazon Seller order.

For more information, see https://developer-docs.amazon.com/sp-api/docs/orders-api-v0-reference#getorders

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    String sOrderId
    Variant vAuthAws
    Handle hoAuthAws
    Handle hoJsonLwaToken
    Boolean iSuccess
    Handle hoRest
    String sLwa_token
    Handle hoSbPath
    Handle hoJsonRc
    Variant vSbRequest
    Handle hoSbRequest
    Variant vSbResponse
    Handle hoSbResponse
    String sUri
    Integer iStatusCode
    Handle hoJsonResp
    String sRestrictedDataToken
    Handle hoJson
    String sStrVal
    String sAmazonOrderId
    String sPurchaseDate
    String sLastUpdateDate
    String sOrderStatus
    String sFulfillmentChannel
    String sSalesChannel
    String sShipServiceLevel
    String sCurrencyCode
    String sAmount
    Integer iNumberOfItemsShipped
    Integer iNumberOfItemsUnshipped
    String sPaymentMethod
    Boolean iIsReplacementOrder
    String sMarketplaceId
    String sShipmentServiceLevelCategory
    String sOrderType
    String sEarliestShipDate
    String sLatestShipDate
    String sEarliestDeliveryDate
    String sLatestDeliveryDate
    Boolean iIsBusinessOrder
    Boolean iIsPrime
    Boolean iIsGlobalExpressEnabled
    Boolean iIsPremiumOrder
    Boolean iIsSoldByAB
    Boolean iIsIBA
    String sName
    String sAddressLine1
    String sCity
    String sStateOrRegion
    String sPostalCode
    String sCountryCode
    String sPhone
    String sAddressType
    String sFulfillmentSupplySourceId
    Boolean iIsISPU
    Boolean iIsAccessPointOrder
    Boolean iHasAutomatedShippingSettings
    String sEasyShipShipmentStatus
    String sElectronicInvoiceStatus
    Integer i
    Integer iCount_i
    String sTemp1

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

    // Gets information for this order ID
    // The order ID is something like "902-1845936-5435065" and it is the AmazonOrderId returned in the JSON when getting the list of orders.  For example:
    // {
    //   "payload": {
    //     "CreatedBefore": "1.569521782042E9",
    //     "Orders": [
    //       {
    //         "AmazonOrderId": "902-1845936-5435065",
    //         "PurchaseDate": "1970-01-19T03:58:30Z",
    // ...

    // However, when using the sandbox, instead use the explicit keyword TEST_CASE_200
    Move "TEST_CASE_200" To sOrderId

    Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
    If (Not(IsComObjectCreated(hoAuthAws))) Begin
        Send CreateComObject of hoAuthAws
    End
    Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
    Set ComSecretKey Of hoAuthAws To "AWS_SECRET_KEY"
    Set ComServiceName Of hoAuthAws To "execute-api"
    // Use the region that is correct for your needs.
    Set ComRegion Of hoAuthAws To "eu-west-1"

    // First get a restricted data token for the given order ID.
    // This requires an LWA access token which cannot be more than 1 hour old.
    // See Fetch SP-API LWA Access Token
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonLwaToken
    If (Not(IsComObjectCreated(hoJsonLwaToken))) Begin
        Send CreateComObject of hoJsonLwaToken
    End
    Get ComLoadFile Of hoJsonLwaToken "qa_data/tokens/sp_api_lwa_token.json" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load LWA access token."
        Procedure_Return
    End

    // Must use the non-sandbox domain for getting the RDT.
    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Get ComConnect Of hoRest "sellingpartnerapi-eu.amazon.com" 443 True True To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoAuthAws to vAuthAws
    Get ComSetAuthAws Of hoRest vAuthAws To iSuccess

    // Add the x-amz-access-token request header.
    Get ComStringOf Of hoJsonLwaToken "access_token" To sLwa_token
    Get ComClearAllHeaders Of hoRest To iSuccess
    Get ComAddHeader Of hoRest "x-amz-access-token" sLwa_token To iSuccess

    // We're going to send a POST with the following JSON body:

    // {
    //   "restrictedResources": [
    //     {
    //       "method": "GET",
    //       "path": "/orders/v0/orders/{orderId}",
    //       "dataElements": ["buyerInfo", "shippingAddress"]
    //     }
    //   ]
    // }

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPath
    If (Not(IsComObjectCreated(hoSbPath))) Begin
        Send CreateComObject of hoSbPath
    End
    Get ComAppend Of hoSbPath "/orders/v0/orders/" To iSuccess
    Get ComAppend Of hoSbPath sOrderId To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonRc
    If (Not(IsComObjectCreated(hoJsonRc))) Begin
        Send CreateComObject of hoJsonRc
    End
    Get ComUpdateString Of hoJsonRc "restrictedResources[0].method" "GET" To iSuccess
    Get ComGetAsString Of hoSbPath To sTemp1
    Get ComUpdateString Of hoJsonRc "restrictedResources[0].path" sTemp1 To iSuccess
    Get ComUpdateString Of hoJsonRc "restrictedResources[0].dataElements[0]" "buyerInfo" To iSuccess
    Get ComUpdateString Of hoJsonRc "restrictedResources[0].dataElements[1]" "shippingAddress" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequest
    If (Not(IsComObjectCreated(hoSbRequest))) Begin
        Send CreateComObject of hoSbRequest
    End
    Get pvComObject of hoSbRequest to vSbRequest
    Get ComEmitSb Of hoJsonRc vSbRequest To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
    If (Not(IsComObjectCreated(hoSbResponse))) Begin
        Send CreateComObject of hoSbResponse
    End
    Move "/tokens/2021-03-01/restrictedDataToken" To sUri
    Get pvComObject of hoSbRequest to vSbRequest
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComFullRequestSb Of hoRest "POST" sUri vSbRequest vSbResponse To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine the response status.
    Get ComResponseStatusCode Of hoRest To iStatusCode
    If (iStatusCode <> 200) Begin
        Showln "Response status code: " iStatusCode
        Get ComResponseStatusText Of hoRest To sTemp1
        Showln "Response status text: " sTemp1
        Showln "Response body: "
        Get ComGetAsString Of hoSbResponse To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    // Get the restricted data token.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResp
    If (Not(IsComObjectCreated(hoJsonResp))) Begin
        Send CreateComObject of hoJsonResp
    End
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComLoadSb Of hoJsonResp vSbResponse To iSuccess
    Get ComStringOf Of hoJsonResp "restrictedDataToken" To sRestrictedDataToken
    Showln "Restricted Data Token: " sRestrictedDataToken

    // ------------------------------------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------------------------------------
    // Now that we have the RDT, we can use it to get information about the order.
    // 
    // Yes, the SP-API is horribly tedious and painful.  You must use an RDT specifically tailored to each request requiring an RDT,
    // the RDT must not be over an hour old, and if you need to get a new RDT you must get it using an LWA token that itself is not
    // more than an hour old.  If the LWA is more than an hour old, you must get a new one.  Ughhh!!!!!
    // ------------------------------------------------------------------------------------------------------------

    // Disconnect from the non-sandbox domain.  This example will use the sandbox.
    // (The RDT was obtained using the non-sandbox domain.  For some reason, the sandbox domain does not work for getting the RDT.)
    Get ComDisconnect Of hoRest 100 To iSuccess

    Get ComConnect Of hoRest "sandbox.sellingpartnerapi-eu.amazon.com" 443 True True To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoAuthAws to vAuthAws
    Get ComSetAuthAws Of hoRest vAuthAws To iSuccess

    Get ComClearAllHeaders Of hoRest To iSuccess
    Get ComAddHeader Of hoRest "x-amz-access-token" sRestrictedDataToken To iSuccess

    Get ComClearAllQueryParams Of hoRest To iSuccess
    Get ComAddQueryParam Of hoRest "MarketplaceIds" "ATVPDKIKX0DER" To iSuccess

    Get ComClearAllPathParams Of hoRest To iSuccess
    Get ComAddPathParam Of hoRest "{orderId}" sOrderId To iSuccess

    Move "/orders/v0/orders/{orderId}" To sUri
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComFullRequestNoBodySb Of hoRest "GET" sUri vSbResponse To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine the response status.
    Get ComResponseStatusCode Of hoRest To iStatusCode
    If (iStatusCode <> 200) Begin
        Get ComResponseStatusText Of hoRest To sTemp1
        Showln "Response status text: " sTemp1
        Showln "Response body: "
        Get ComGetAsString Of hoSbResponse To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    Get ComGetAsString Of hoSbResponse To sTemp1
    Showln sTemp1

    // If successful, gets a JSON response such as the following:

    // {
    //   "payload": {
    //     "AmazonOrderId": "902-1845936-5435065",
    //     "PurchaseDate": "1970-01-19T03:58:30Z",
    //     "LastUpdateDate": "1970-01-19T03:58:32Z",
    //     "OrderStatus": "Unshipped",
    //     "FulfillmentChannel": "MFN",
    //     "SalesChannel": "Amazon.com",
    //     "ShipServiceLevel": "Std US D2D Dom",
    //     "OrderTotal": {
    //       "CurrencyCode": "USD",
    //       "Amount": "11.01"
    //     },
    //     "NumberOfItemsShipped": 0,
    //     "NumberOfItemsUnshipped": 1,
    //     "PaymentMethod": "Other",
    //     "PaymentMethodDetails": [
    //       "Standard"
    //     ],
    //     "IsReplacementOrder": false,
    //     "MarketplaceId": "ATVPDKIKX0DER",
    //     "ShipmentServiceLevelCategory": "Standard",
    //     "OrderType": "StandardOrder",
    //     "EarliestShipDate": "1970-01-19T03:59:27Z",
    //     "LatestShipDate": "1970-01-19T04:05:13Z",
    //     "EarliestDeliveryDate": "1970-01-19T04:06:39Z",
    //     "LatestDeliveryDate": "1970-01-19T04:15:17Z",
    //     "IsBusinessOrder": false,
    //     "IsPrime": false,
    //     "IsGlobalExpressEnabled": false,
    //     "IsPremiumOrder": false,
    //     "IsSoldByAB": false,
    //     "IsIBA": false,
    //     "DefaultShipFromLocationAddress": {
    //       "Name": "MFNIntegrationTestMerchant",
    //       "AddressLine1": "2201 WESTLAKE AVE",
    //       "City": "SEATTLE",
    //       "StateOrRegion": "WA",
    //       "PostalCode": "98121-2778",
    //       "CountryCode": "US",
    //       "Phone": "+1 480-386-0930 ext. 73824",
    //       "AddressType": "Commercial"
    //     },
    //     "FulfillmentInstruction": {
    //       "FulfillmentSupplySourceId": "sampleSupplySourceId"
    //     },
    //     "IsISPU": false,
    //     "IsAccessPointOrder": false,
    //     "AutomatedShippingSettings": {
    //       "HasAutomatedShippingSettings": false
    //     },
    //     "EasyShipShipmentStatus": "PendingPickUp",
    //     "ElectronicInvoiceStatus": "NotRequired"
    //   }
    // }

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End

    Get pvComObject of hoSbResponse to vSbResponse
    Get ComLoadSb Of hoJson vSbResponse To iSuccess

    Get ComStringOf Of hoJson "payload.AmazonOrderId" To sAmazonOrderId
    Get ComStringOf Of hoJson "payload.PurchaseDate" To sPurchaseDate
    Get ComStringOf Of hoJson "payload.LastUpdateDate" To sLastUpdateDate
    Get ComStringOf Of hoJson "payload.OrderStatus" To sOrderStatus
    Get ComStringOf Of hoJson "payload.FulfillmentChannel" To sFulfillmentChannel
    Get ComStringOf Of hoJson "payload.SalesChannel" To sSalesChannel
    Get ComStringOf Of hoJson "payload.ShipServiceLevel" To sShipServiceLevel
    Get ComStringOf Of hoJson "payload.OrderTotal.CurrencyCode" To sCurrencyCode
    Get ComStringOf Of hoJson "payload.OrderTotal.Amount" To sAmount
    Get ComIntOf Of hoJson "payload.NumberOfItemsShipped" To iNumberOfItemsShipped
    Get ComIntOf Of hoJson "payload.NumberOfItemsUnshipped" To iNumberOfItemsUnshipped
    Get ComStringOf Of hoJson "payload.PaymentMethod" To sPaymentMethod
    Get ComBoolOf Of hoJson "payload.IsReplacementOrder" To iIsReplacementOrder
    Get ComStringOf Of hoJson "payload.MarketplaceId" To sMarketplaceId
    Get ComStringOf Of hoJson "payload.ShipmentServiceLevelCategory" To sShipmentServiceLevelCategory
    Get ComStringOf Of hoJson "payload.OrderType" To sOrderType
    Get ComStringOf Of hoJson "payload.EarliestShipDate" To sEarliestShipDate
    Get ComStringOf Of hoJson "payload.LatestShipDate" To sLatestShipDate
    Get ComStringOf Of hoJson "payload.EarliestDeliveryDate" To sEarliestDeliveryDate
    Get ComStringOf Of hoJson "payload.LatestDeliveryDate" To sLatestDeliveryDate
    Get ComBoolOf Of hoJson "payload.IsBusinessOrder" To iIsBusinessOrder
    Get ComBoolOf Of hoJson "payload.IsPrime" To iIsPrime
    Get ComBoolOf Of hoJson "payload.IsGlobalExpressEnabled" To iIsGlobalExpressEnabled
    Get ComBoolOf Of hoJson "payload.IsPremiumOrder" To iIsPremiumOrder
    Get ComBoolOf Of hoJson "payload.IsSoldByAB" To iIsSoldByAB
    Get ComBoolOf Of hoJson "payload.IsIBA" To iIsIBA
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.Name" To sName
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.AddressLine1" To sAddressLine1
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.City" To sCity
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.StateOrRegion" To sStateOrRegion
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.PostalCode" To sPostalCode
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.CountryCode" To sCountryCode
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.Phone" To sPhone
    Get ComStringOf Of hoJson "payload.DefaultShipFromLocationAddress.AddressType" To sAddressType
    Get ComStringOf Of hoJson "payload.FulfillmentInstruction.FulfillmentSupplySourceId" To sFulfillmentSupplySourceId
    Get ComBoolOf Of hoJson "payload.IsISPU" To iIsISPU
    Get ComBoolOf Of hoJson "payload.IsAccessPointOrder" To iIsAccessPointOrder
    Get ComBoolOf Of hoJson "payload.AutomatedShippingSettings.HasAutomatedShippingSettings" To iHasAutomatedShippingSettings
    Get ComStringOf Of hoJson "payload.EasyShipShipmentStatus" To sEasyShipShipmentStatus
    Get ComStringOf Of hoJson "payload.ElectronicInvoiceStatus" To sElectronicInvoiceStatus
    Move 0 To i
    Get ComSizeOfArray Of hoJson "payload.PaymentMethodDetails" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJson To i
        Get ComStringOf Of hoJson "payload.PaymentMethodDetails[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Showln "Success!"


End_Procedure

 

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