Sample code for 30+ languages & platforms
AutoIt

Amazon SP-API Get Orders

See more Amazon SP-API Examples

Demonstrates Amazon SP-API Sellers API -- get orders. Returns orders created or updated during the time frame indicated by the specified parameters.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

; IMPORTANT:
; You'll need to make changes to use values specific to your own region and account.
; 
; Here is a list of values you'll need to change or provide:
; 
; 1) The access key. Change AWS_ACCESS_KEY to your actual access key.
; 2) The secret key. Change AWS_SECRET_KEY to your actual access key.
; 3) Your region.  Change "ew-west-1" to your region.
; 4) The domain to which you connect.  Change sandbox.sellingpartnerapi-eu.amazon.com to non-sandbox by removing the "sandbox." 
;    and change the "-eu" part of the domain to your region. See https://developer-docs.amazon.com/sp-api/docs/sp-api-endpoints
; 5) Use the restricted data token (RDT) obtained from your code that previously obtained the RDT.
; 	If you saved the RDT to a file, update the relative file path "qa_data/tokens/sp_api_rdt_token.json" to your actual file path.
; 6) Update your Marketplace ID(s), such as ATVPDKIKX0DER
; 7) If using the non-sandbox, change the CreatedAfter from "TEST_CASE_200" to an actual date, such as "2022-12-25"

$oAuthAws = ObjCreate("Chilkat.AuthAws")
$oAuthAws.AccessKey = "AWS_ACCESS_KEY"
$oAuthAws.SecretKey = "AWS_SECRET_KEY"
$oAuthAws.ServiceName = "execute-api"
; Use the region that is correct for your needs.
$oAuthAws.Region = "eu-west-1"

$oRest = ObjCreate("Chilkat.Rest")
Local $bTls = True
Local $iPort = 443
Local $bAutoReconnect = True
; Make sure to use the correct domain.
; This example is using the sandbox
$bSuccess = $oRest.Connect("sandbox.sellingpartnerapi-eu.amazon.com",$iPort,$bTls,$bAutoReconnect)
If ($bSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oRest.SetAuthAws($oAuthAws)

; Here's the example to get the RDT access token: Get SP-API Restricted Data Token

; Load the previously obtained RDT access token.
; See Fetch SP-API RDT Access Token
$oJsonToken = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/sp_api_rdt_token.json")
If ($bSuccess = False) Then
    ConsoleWrite("Failed to load RDT access token." & @CRLF)
    Exit
EndIf

; Add the x-amz-access-token request header.
Local $sRdt_token = $oJsonToken.StringOf("restrictedDataToken")
$oRest.ClearAllHeaders()
$oRest.AddHeader("x-amz-access-token",$sRdt_token)

; Indicate the marketplace IDs.  Use the marketplace ID for your needs. See https://developer-docs.amazon.com/sp-api/docs/marketplace-ids
$oRest.ClearAllQueryParams()
; When using the sandbox, use these params literally and exactly has shown here:
$oRest.AddQueryParam("MarketplaceIds","ATVPDKIKX0DER")
$oRest.AddQueryParam("CreatedAfter","TEST_CASE_200")

$oSbResponse = ObjCreate("Chilkat.StringBuilder")
Local $sUri = "/orders/v0/orders"
$bSuccess = $oRest.FullRequestNoBodySb("GET",$sUri,$oSbResponse)
If ($bSuccess = False) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

; Examine the response status.
Local $iStatusCode = $oRest.ResponseStatusCode
If ($iStatusCode <> 200) Then
    ConsoleWrite("Response status text: " & $oRest.ResponseStatusText & @CRLF)
    ConsoleWrite("Response body: " & @CRLF)
    ConsoleWrite($oSbResponse.GetAsString() & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

ConsoleWrite($oSbResponse.GetAsString() & @CRLF)

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

; {
;   "payload": {
;     "CreatedBefore": "1.569521782042E9",
;     "Orders": [
;       {
;         "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"
;       },
;       {
;         "AmazonOrderId": "902-8745147-1934268",
;         "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,
;         "IsAccessPointOrder": false,
;         "IsGlobalExpressEnabled": false,
;         "IsPremiumOrder": false,
;         "IsSoldByAB": false,
;         "IsIBA": false,
;         "EasyShipShipmentStatus": "PendingPickUp",
;         "ElectronicInvoiceStatus": "NotRequired"
;       }
;     ]
;   }
; }

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

$oJson = ObjCreate("Chilkat.JsonObject")

$oJson.LoadSb($oSbResponse)

Local $sAmazonOrderId
Local $sPurchaseDate
Local $sLastUpdateDate
Local $sOrderStatus
Local $sFulfillmentChannel
Local $sSalesChannel
Local $sShipServiceLevel
Local $sCurrencyCode
Local $sAmount
Local $iNumberOfItemsShipped
Local $iNumberOfItemsUnshipped
Local $sPaymentMethod
Local $bIsReplacementOrder
Local $sMarketplaceId
Local $sShipmentServiceLevelCategory
Local $sOrderType
Local $sEarliestShipDate
Local $sLatestShipDate
Local $sEarliestDeliveryDate
Local $sLatestDeliveryDate
Local $bIsBusinessOrder
Local $bIsPrime
Local $bIsGlobalExpressEnabled
Local $bIsPremiumOrder
Local $bIsSoldByAB
Local $bIsIBA
Local $sName
Local $sAddressLine1
Local $sCity
Local $sStateOrRegion
Local $sPostalCode
Local $sCountryCode
Local $sPhone
Local $sAddressType
Local $sFulfillmentSupplySourceId
Local $bIsISPU
Local $bIsAccessPointOrder
Local $bHasAutomatedShippingSettings
Local $sEasyShipShipmentStatus
Local $sElectronicInvoiceStatus
Local $iJ
Local $iCount_j
Local $strVal

Local $sCreatedBefore = $oJson.StringOf("payload.CreatedBefore")
Local $i = 0
Local $iCount_i = $oJson.SizeOfArray("payload.Orders")
While $i < $iCount_i
    $oJson.I = $i
    $sAmazonOrderId = $oJson.StringOf("payload.Orders[i].AmazonOrderId")
    $sPurchaseDate = $oJson.StringOf("payload.Orders[i].PurchaseDate")
    $sLastUpdateDate = $oJson.StringOf("payload.Orders[i].LastUpdateDate")
    $sOrderStatus = $oJson.StringOf("payload.Orders[i].OrderStatus")
    $sFulfillmentChannel = $oJson.StringOf("payload.Orders[i].FulfillmentChannel")
    $sSalesChannel = $oJson.StringOf("payload.Orders[i].SalesChannel")
    $sShipServiceLevel = $oJson.StringOf("payload.Orders[i].ShipServiceLevel")
    $sCurrencyCode = $oJson.StringOf("payload.Orders[i].OrderTotal.CurrencyCode")
    $sAmount = $oJson.StringOf("payload.Orders[i].OrderTotal.Amount")
    $iNumberOfItemsShipped = $oJson.IntOf("payload.Orders[i].NumberOfItemsShipped")
    $iNumberOfItemsUnshipped = $oJson.IntOf("payload.Orders[i].NumberOfItemsUnshipped")
    $sPaymentMethod = $oJson.StringOf("payload.Orders[i].PaymentMethod")
    $bIsReplacementOrder = $oJson.BoolOf("payload.Orders[i].IsReplacementOrder")
    $sMarketplaceId = $oJson.StringOf("payload.Orders[i].MarketplaceId")
    $sShipmentServiceLevelCategory = $oJson.StringOf("payload.Orders[i].ShipmentServiceLevelCategory")
    $sOrderType = $oJson.StringOf("payload.Orders[i].OrderType")
    $sEarliestShipDate = $oJson.StringOf("payload.Orders[i].EarliestShipDate")
    $sLatestShipDate = $oJson.StringOf("payload.Orders[i].LatestShipDate")
    $sEarliestDeliveryDate = $oJson.StringOf("payload.Orders[i].EarliestDeliveryDate")
    $sLatestDeliveryDate = $oJson.StringOf("payload.Orders[i].LatestDeliveryDate")
    $bIsBusinessOrder = $oJson.BoolOf("payload.Orders[i].IsBusinessOrder")
    $bIsPrime = $oJson.BoolOf("payload.Orders[i].IsPrime")
    $bIsGlobalExpressEnabled = $oJson.BoolOf("payload.Orders[i].IsGlobalExpressEnabled")
    $bIsPremiumOrder = $oJson.BoolOf("payload.Orders[i].IsPremiumOrder")
    $bIsSoldByAB = $oJson.BoolOf("payload.Orders[i].IsSoldByAB")
    $bIsIBA = $oJson.BoolOf("payload.Orders[i].IsIBA")
    $sName = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.Name")
    $sAddressLine1 = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.AddressLine1")
    $sCity = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.City")
    $sStateOrRegion = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.StateOrRegion")
    $sPostalCode = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.PostalCode")
    $sCountryCode = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.CountryCode")
    $sPhone = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.Phone")
    $sAddressType = $oJson.StringOf("payload.Orders[i].DefaultShipFromLocationAddress.AddressType")
    $sFulfillmentSupplySourceId = $oJson.StringOf("payload.Orders[i].FulfillmentInstruction.FulfillmentSupplySourceId")
    $bIsISPU = $oJson.BoolOf("payload.Orders[i].IsISPU")
    $bIsAccessPointOrder = $oJson.BoolOf("payload.Orders[i].IsAccessPointOrder")
    $bHasAutomatedShippingSettings = $oJson.BoolOf("payload.Orders[i].AutomatedShippingSettings.HasAutomatedShippingSettings")
    $sEasyShipShipmentStatus = $oJson.StringOf("payload.Orders[i].EasyShipShipmentStatus")
    $sElectronicInvoiceStatus = $oJson.StringOf("payload.Orders[i].ElectronicInvoiceStatus")
    $iJ = 0
    $iCount_j = $oJson.SizeOfArray("payload.Orders[i].PaymentMethodDetails")
    While $iJ < $iCount_j
        $oJson.J = $iJ
        $strVal = $oJson.StringOf("payload.Orders[i].PaymentMethodDetails[j]")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

ConsoleWrite("Success!" & @CRLF)