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
(Unicode C) 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
#include <C_CkAuthAwsW.h> #include <C_CkRestW.h> #include <C_CkJsonObjectW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkAuthAwsW authAws; HCkRestW rest; BOOL bTls; int port; BOOL bAutoReconnect; BOOL success; HCkJsonObjectW jsonToken; const wchar_t *rdt_token; HCkStringBuilderW sbResponse; const wchar_t *uri; int statusCode; HCkJsonObjectW json; const wchar_t *AmazonOrderId; const wchar_t *PurchaseDate; const wchar_t *LastUpdateDate; const wchar_t *OrderStatus; const wchar_t *FulfillmentChannel; const wchar_t *SalesChannel; const wchar_t *ShipServiceLevel; const wchar_t *CurrencyCode; const wchar_t *Amount; int NumberOfItemsShipped; int NumberOfItemsUnshipped; const wchar_t *PaymentMethod; BOOL IsReplacementOrder; const wchar_t *MarketplaceId; const wchar_t *ShipmentServiceLevelCategory; const wchar_t *OrderType; const wchar_t *EarliestShipDate; const wchar_t *LatestShipDate; const wchar_t *EarliestDeliveryDate; const wchar_t *LatestDeliveryDate; BOOL IsBusinessOrder; BOOL IsPrime; BOOL IsGlobalExpressEnabled; BOOL IsPremiumOrder; BOOL IsSoldByAB; BOOL IsIBA; const wchar_t *Name; const wchar_t *AddressLine1; const wchar_t *City; const wchar_t *StateOrRegion; const wchar_t *PostalCode; const wchar_t *CountryCode; const wchar_t *Phone; const wchar_t *AddressType; const wchar_t *FulfillmentSupplySourceId; BOOL IsISPU; BOOL IsAccessPointOrder; BOOL HasAutomatedShippingSettings; const wchar_t *EasyShipShipmentStatus; const wchar_t *ElectronicInvoiceStatus; int j; int count_j; const wchar_t *strVal; const wchar_t *CreatedBefore; int i; int count_i; // 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 = CkAuthAwsW_Create(); CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY"); CkAuthAwsW_putSecretKey(authAws,L"AWS_SECRET_KEY"); CkAuthAwsW_putServiceName(authAws,L"execute-api"); // Use the region that is correct for your needs. CkAuthAwsW_putRegion(authAws,L"eu-west-1"); rest = CkRestW_Create(); bTls = TRUE; port = 443; bAutoReconnect = TRUE; // Make sure to use the correct domain. // This example is using the sandbox success = CkRestW_Connect(rest,L"sandbox.sellingpartnerapi-eu.amazon.com",port,bTls,bAutoReconnect); if (success == FALSE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); return; } success = CkRestW_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 = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/sp_api_rdt_token.json"); if (success == FALSE) { wprintf(L"Failed to load RDT access token.\n"); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); return; } // Add the x-amz-access-token request header. rdt_token = CkJsonObjectW_stringOf(jsonToken,L"restrictedDataToken"); CkRestW_ClearAllHeaders(rest); CkRestW_AddHeader(rest,L"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 CkRestW_ClearAllQueryParams(rest); // When using the sandbox, use these params literally and exactly has shown here: CkRestW_AddQueryParam(rest,L"MarketplaceIds",L"ATVPDKIKX0DER"); CkRestW_AddQueryParam(rest,L"CreatedAfter",L"TEST_CASE_200"); sbResponse = CkStringBuilderW_Create(); uri = L"/orders/v0/orders"; success = CkRestW_FullRequestNoBodySb(rest,L"GET",uri,sbResponse); if (success == FALSE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); CkStringBuilderW_Dispose(sbResponse); return; } // Examine the response status. statusCode = CkRestW_getResponseStatusCode(rest); if (statusCode != 200) { wprintf(L"Response status text: %s\n",CkRestW_responseStatusText(rest)); wprintf(L"Response body: \n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponse)); wprintf(L"Failed.\n"); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); CkStringBuilderW_Dispose(sbResponse); return; } wprintf(L"%s\n",CkStringBuilderW_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 = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(json,sbResponse); CreatedBefore = CkJsonObjectW_stringOf(json,L"payload.CreatedBefore"); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"payload.Orders"); while (i < count_i) { CkJsonObjectW_putI(json,i); AmazonOrderId = CkJsonObjectW_stringOf(json,L"payload.Orders[i].AmazonOrderId"); PurchaseDate = CkJsonObjectW_stringOf(json,L"payload.Orders[i].PurchaseDate"); LastUpdateDate = CkJsonObjectW_stringOf(json,L"payload.Orders[i].LastUpdateDate"); OrderStatus = CkJsonObjectW_stringOf(json,L"payload.Orders[i].OrderStatus"); FulfillmentChannel = CkJsonObjectW_stringOf(json,L"payload.Orders[i].FulfillmentChannel"); SalesChannel = CkJsonObjectW_stringOf(json,L"payload.Orders[i].SalesChannel"); ShipServiceLevel = CkJsonObjectW_stringOf(json,L"payload.Orders[i].ShipServiceLevel"); CurrencyCode = CkJsonObjectW_stringOf(json,L"payload.Orders[i].OrderTotal.CurrencyCode"); Amount = CkJsonObjectW_stringOf(json,L"payload.Orders[i].OrderTotal.Amount"); NumberOfItemsShipped = CkJsonObjectW_IntOf(json,L"payload.Orders[i].NumberOfItemsShipped"); NumberOfItemsUnshipped = CkJsonObjectW_IntOf(json,L"payload.Orders[i].NumberOfItemsUnshipped"); PaymentMethod = CkJsonObjectW_stringOf(json,L"payload.Orders[i].PaymentMethod"); IsReplacementOrder = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsReplacementOrder"); MarketplaceId = CkJsonObjectW_stringOf(json,L"payload.Orders[i].MarketplaceId"); ShipmentServiceLevelCategory = CkJsonObjectW_stringOf(json,L"payload.Orders[i].ShipmentServiceLevelCategory"); OrderType = CkJsonObjectW_stringOf(json,L"payload.Orders[i].OrderType"); EarliestShipDate = CkJsonObjectW_stringOf(json,L"payload.Orders[i].EarliestShipDate"); LatestShipDate = CkJsonObjectW_stringOf(json,L"payload.Orders[i].LatestShipDate"); EarliestDeliveryDate = CkJsonObjectW_stringOf(json,L"payload.Orders[i].EarliestDeliveryDate"); LatestDeliveryDate = CkJsonObjectW_stringOf(json,L"payload.Orders[i].LatestDeliveryDate"); IsBusinessOrder = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsBusinessOrder"); IsPrime = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsPrime"); IsGlobalExpressEnabled = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsGlobalExpressEnabled"); IsPremiumOrder = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsPremiumOrder"); IsSoldByAB = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsSoldByAB"); IsIBA = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsIBA"); Name = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.Name"); AddressLine1 = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.AddressLine1"); City = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.City"); StateOrRegion = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.StateOrRegion"); PostalCode = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.PostalCode"); CountryCode = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.CountryCode"); Phone = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.Phone"); AddressType = CkJsonObjectW_stringOf(json,L"payload.Orders[i].DefaultShipFromLocationAddress.AddressType"); FulfillmentSupplySourceId = CkJsonObjectW_stringOf(json,L"payload.Orders[i].FulfillmentInstruction.FulfillmentSupplySourceId"); IsISPU = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsISPU"); IsAccessPointOrder = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].IsAccessPointOrder"); HasAutomatedShippingSettings = CkJsonObjectW_BoolOf(json,L"payload.Orders[i].AutomatedShippingSettings.HasAutomatedShippingSettings"); EasyShipShipmentStatus = CkJsonObjectW_stringOf(json,L"payload.Orders[i].EasyShipShipmentStatus"); ElectronicInvoiceStatus = CkJsonObjectW_stringOf(json,L"payload.Orders[i].ElectronicInvoiceStatus"); j = 0; count_j = CkJsonObjectW_SizeOfArray(json,L"payload.Orders[i].PaymentMethodDetails"); while (j < count_j) { CkJsonObjectW_putJ(json,j); strVal = CkJsonObjectW_stringOf(json,L"payload.Orders[i].PaymentMethodDetails[j]"); j = j + 1; } i = i + 1; } wprintf(L"Success!\n"); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); CkStringBuilderW_Dispose(sbResponse); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.