Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Amazon SP-API Get OrdersSee more Amazon SP-API ExamplesDemonstrates Amazon SP-API Sellers API -- get orders. Returns orders created or updated during the time frame indicated by the specified parameters. For more information, see https://developer-docs.amazon.com/sp-api/docs/orders-api-v0-reference#getorders
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AuthAws, Rest, JsonObject, StringBuilder; ... procedure TForm1.Button1Click(Sender: TObject); var authAws: HCkAuthAws; rest: HCkRest; bTls: Boolean; port: Integer; bAutoReconnect: Boolean; success: Boolean; jsonToken: HCkJsonObject; rdt_token: PWideChar; sbResponse: HCkStringBuilder; uri: PWideChar; statusCode: Integer; json: HCkJsonObject; AmazonOrderId: PWideChar; PurchaseDate: PWideChar; LastUpdateDate: PWideChar; OrderStatus: PWideChar; FulfillmentChannel: PWideChar; SalesChannel: PWideChar; ShipServiceLevel: PWideChar; CurrencyCode: PWideChar; Amount: PWideChar; NumberOfItemsShipped: Integer; NumberOfItemsUnshipped: Integer; PaymentMethod: PWideChar; IsReplacementOrder: Boolean; MarketplaceId: PWideChar; ShipmentServiceLevelCategory: PWideChar; OrderType: PWideChar; EarliestShipDate: PWideChar; LatestShipDate: PWideChar; EarliestDeliveryDate: PWideChar; LatestDeliveryDate: PWideChar; IsBusinessOrder: Boolean; IsPrime: Boolean; IsGlobalExpressEnabled: Boolean; IsPremiumOrder: Boolean; IsSoldByAB: Boolean; IsIBA: Boolean; Name: PWideChar; AddressLine1: PWideChar; City: PWideChar; StateOrRegion: PWideChar; PostalCode: PWideChar; CountryCode: PWideChar; Phone: PWideChar; AddressType: PWideChar; FulfillmentSupplySourceId: PWideChar; IsISPU: Boolean; IsAccessPointOrder: Boolean; HasAutomatedShippingSettings: Boolean; EasyShipShipmentStatus: PWideChar; ElectronicInvoiceStatus: PWideChar; j: Integer; count_j: Integer; strVal: PWideChar; CreatedBefore: PWideChar; i: Integer; count_i: Integer; begin // 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" authAws := CkAuthAws_Create(); CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY'); CkAuthAws_putSecretKey(authAws,'AWS_SECRET_KEY'); CkAuthAws_putServiceName(authAws,'execute-api'); // Use the region that is correct for your needs. CkAuthAws_putRegion(authAws,'eu-west-1'); rest := CkRest_Create(); bTls := True; port := 443; bAutoReconnect := True; // Make sure to use the correct domain. // This example is using the sandbox success := CkRest_Connect(rest,'sandbox.sellingpartnerapi-eu.amazon.com',port,bTls,bAutoReconnect); if (success = False) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; success := CkRest_SetAuthAws(rest,authAws); // 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 jsonToken := CkJsonObject_Create(); success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/sp_api_rdt_token.json'); if (success = False) then begin Memo1.Lines.Add('Failed to load RDT access token.'); Exit; end; // Add the x-amz-access-token request header. rdt_token := CkJsonObject__stringOf(jsonToken,'restrictedDataToken'); CkRest_ClearAllHeaders(rest); CkRest_AddHeader(rest,'x-amz-access-token',rdt_token); // Indicate the marketplace IDs. Use the marketplace ID for your needs. See https://developer-docs.amazon.com/sp-api/docs/marketplace-ids CkRest_ClearAllQueryParams(rest); // When using the sandbox, use these params literally and exactly has shown here: CkRest_AddQueryParam(rest,'MarketplaceIds','ATVPDKIKX0DER'); CkRest_AddQueryParam(rest,'CreatedAfter','TEST_CASE_200'); sbResponse := CkStringBuilder_Create(); uri := '/orders/v0/orders'; success := CkRest_FullRequestNoBodySb(rest,'GET',uri,sbResponse); if (success = False) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; // Examine the response status. statusCode := CkRest_getResponseStatusCode(rest); if (statusCode <> 200) then begin Memo1.Lines.Add('Response status text: ' + CkRest__responseStatusText(rest)); Memo1.Lines.Add('Response body: '); Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponse)); Memo1.Lines.Add('Failed.'); Exit; end; Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponse)); // 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 json := CkJsonObject_Create(); CkJsonObject_LoadSb(json,sbResponse); CreatedBefore := CkJsonObject__stringOf(json,'payload.CreatedBefore'); i := 0; count_i := CkJsonObject_SizeOfArray(json,'payload.Orders'); while i < count_i do begin CkJsonObject_putI(json,i); AmazonOrderId := CkJsonObject__stringOf(json,'payload.Orders[i].AmazonOrderId'); PurchaseDate := CkJsonObject__stringOf(json,'payload.Orders[i].PurchaseDate'); LastUpdateDate := CkJsonObject__stringOf(json,'payload.Orders[i].LastUpdateDate'); OrderStatus := CkJsonObject__stringOf(json,'payload.Orders[i].OrderStatus'); FulfillmentChannel := CkJsonObject__stringOf(json,'payload.Orders[i].FulfillmentChannel'); SalesChannel := CkJsonObject__stringOf(json,'payload.Orders[i].SalesChannel'); ShipServiceLevel := CkJsonObject__stringOf(json,'payload.Orders[i].ShipServiceLevel'); CurrencyCode := CkJsonObject__stringOf(json,'payload.Orders[i].OrderTotal.CurrencyCode'); Amount := CkJsonObject__stringOf(json,'payload.Orders[i].OrderTotal.Amount'); NumberOfItemsShipped := CkJsonObject_IntOf(json,'payload.Orders[i].NumberOfItemsShipped'); NumberOfItemsUnshipped := CkJsonObject_IntOf(json,'payload.Orders[i].NumberOfItemsUnshipped'); PaymentMethod := CkJsonObject__stringOf(json,'payload.Orders[i].PaymentMethod'); IsReplacementOrder := CkJsonObject_BoolOf(json,'payload.Orders[i].IsReplacementOrder'); MarketplaceId := CkJsonObject__stringOf(json,'payload.Orders[i].MarketplaceId'); ShipmentServiceLevelCategory := CkJsonObject__stringOf(json,'payload.Orders[i].ShipmentServiceLevelCategory'); OrderType := CkJsonObject__stringOf(json,'payload.Orders[i].OrderType'); EarliestShipDate := CkJsonObject__stringOf(json,'payload.Orders[i].EarliestShipDate'); LatestShipDate := CkJsonObject__stringOf(json,'payload.Orders[i].LatestShipDate'); EarliestDeliveryDate := CkJsonObject__stringOf(json,'payload.Orders[i].EarliestDeliveryDate'); LatestDeliveryDate := CkJsonObject__stringOf(json,'payload.Orders[i].LatestDeliveryDate'); IsBusinessOrder := CkJsonObject_BoolOf(json,'payload.Orders[i].IsBusinessOrder'); IsPrime := CkJsonObject_BoolOf(json,'payload.Orders[i].IsPrime'); IsGlobalExpressEnabled := CkJsonObject_BoolOf(json,'payload.Orders[i].IsGlobalExpressEnabled'); IsPremiumOrder := CkJsonObject_BoolOf(json,'payload.Orders[i].IsPremiumOrder'); IsSoldByAB := CkJsonObject_BoolOf(json,'payload.Orders[i].IsSoldByAB'); IsIBA := CkJsonObject_BoolOf(json,'payload.Orders[i].IsIBA'); Name := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.Name'); AddressLine1 := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.AddressLine1'); City := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.City'); StateOrRegion := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.StateOrRegion'); PostalCode := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.PostalCode'); CountryCode := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.CountryCode'); Phone := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.Phone'); AddressType := CkJsonObject__stringOf(json,'payload.Orders[i].DefaultShipFromLocationAddress.AddressType'); FulfillmentSupplySourceId := CkJsonObject__stringOf(json,'payload.Orders[i].FulfillmentInstruction.FulfillmentSupplySourceId'); IsISPU := CkJsonObject_BoolOf(json,'payload.Orders[i].IsISPU'); IsAccessPointOrder := CkJsonObject_BoolOf(json,'payload.Orders[i].IsAccessPointOrder'); HasAutomatedShippingSettings := CkJsonObject_BoolOf(json,'payload.Orders[i].AutomatedShippingSettings.HasAutomatedShippingSettings'); EasyShipShipmentStatus := CkJsonObject__stringOf(json,'payload.Orders[i].EasyShipShipmentStatus'); ElectronicInvoiceStatus := CkJsonObject__stringOf(json,'payload.Orders[i].ElectronicInvoiceStatus'); j := 0; count_j := CkJsonObject_SizeOfArray(json,'payload.Orders[i].PaymentMethodDetails'); while j < count_j do begin CkJsonObject_putJ(json,j); strVal := CkJsonObject__stringOf(json,'payload.Orders[i].PaymentMethodDetails[j]'); j := j + 1; end; i := i + 1; end; Memo1.Lines.Add('Success!'); CkAuthAws_Dispose(authAws); CkRest_Dispose(rest); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbResponse); CkJsonObject_Dispose(json); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.