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
(Objective-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
#import <CkoAuthAws.h> #import <CkoRest.h> #import <CkoJsonObject.h> #import <NSString.h> #import <CkoStringBuilder.h> // 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" CkoAuthAws *authAws = [[CkoAuthAws alloc] init]; authAws.AccessKey = @"AWS_ACCESS_KEY"; authAws.SecretKey = @"AWS_SECRET_KEY"; authAws.ServiceName = @"execute-api"; // Use the region that is correct for your needs. authAws.Region = @"eu-west-1"; CkoRest *rest = [[CkoRest alloc] init]; BOOL bTls = YES; int port = 443; BOOL bAutoReconnect = YES; // Make sure to use the correct domain. // This example is using the sandbox BOOL success = [rest Connect: @"sandbox.sellingpartnerapi-eu.amazon.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect]; if (success == NO) { NSLog(@"%@",rest.LastErrorText); return; } success = [rest SetAuthAws: 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 CkoJsonObject *jsonToken = [[CkoJsonObject alloc] init]; success = [jsonToken LoadFile: @"qa_data/tokens/sp_api_rdt_token.json"]; if (success == NO) { NSLog(@"%@",@"Failed to load RDT access token."); return; } // Add the x-amz-access-token request header. NSString *rdt_token = [jsonToken StringOf: @"restrictedDataToken"]; [rest ClearAllHeaders]; [rest AddHeader: @"x-amz-access-token" value: rdt_token]; // Indicate the marketplace IDs. Use the marketplace ID for your needs. See https://developer-docs.amazon.com/sp-api/docs/marketplace-ids [rest ClearAllQueryParams]; // When using the sandbox, use these params literally and exactly has shown here: [rest AddQueryParam: @"MarketplaceIds" value: @"ATVPDKIKX0DER"]; [rest AddQueryParam: @"CreatedAfter" value: @"TEST_CASE_200"]; CkoStringBuilder *sbResponse = [[CkoStringBuilder alloc] init]; NSString *uri = @"/orders/v0/orders"; success = [rest FullRequestNoBodySb: @"GET" uriPath: uri sb: sbResponse]; if (success == NO) { NSLog(@"%@",rest.LastErrorText); return; } // Examine the response status. int statusCode = [rest.ResponseStatusCode intValue]; if (statusCode != 200) { NSLog(@"%@%@",@"Response status text: ",rest.ResponseStatusText); NSLog(@"%@",@"Response body: "); NSLog(@"%@",[sbResponse GetAsString]); NSLog(@"%@",@"Failed."); return; } NSLog(@"%@",[sbResponse GetAsString]); // 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 CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json LoadSb: sbResponse]; NSString *AmazonOrderId = 0; NSString *PurchaseDate = 0; NSString *LastUpdateDate = 0; NSString *OrderStatus = 0; NSString *FulfillmentChannel = 0; NSString *SalesChannel = 0; NSString *ShipServiceLevel = 0; NSString *CurrencyCode = 0; NSString *Amount = 0; int NumberOfItemsShipped; int NumberOfItemsUnshipped; NSString *PaymentMethod = 0; BOOL IsReplacementOrder; NSString *MarketplaceId = 0; NSString *ShipmentServiceLevelCategory = 0; NSString *OrderType = 0; NSString *EarliestShipDate = 0; NSString *LatestShipDate = 0; NSString *EarliestDeliveryDate = 0; NSString *LatestDeliveryDate = 0; BOOL IsBusinessOrder; BOOL IsPrime; BOOL IsGlobalExpressEnabled; BOOL IsPremiumOrder; BOOL IsSoldByAB; BOOL IsIBA; NSString *Name = 0; NSString *AddressLine1 = 0; NSString *City = 0; NSString *StateOrRegion = 0; NSString *PostalCode = 0; NSString *CountryCode = 0; NSString *Phone = 0; NSString *AddressType = 0; NSString *FulfillmentSupplySourceId = 0; BOOL IsISPU; BOOL IsAccessPointOrder; BOOL HasAutomatedShippingSettings; NSString *EasyShipShipmentStatus = 0; NSString *ElectronicInvoiceStatus = 0; int j; int count_j; NSString *strVal = 0; NSString *CreatedBefore = [json StringOf: @"payload.CreatedBefore"]; int i = 0; int count_i = [[json SizeOfArray: @"payload.Orders"] intValue]; while (i < count_i) { json.I = [NSNumber numberWithInt: i]; AmazonOrderId = [json StringOf: @"payload.Orders[i].AmazonOrderId"]; PurchaseDate = [json StringOf: @"payload.Orders[i].PurchaseDate"]; LastUpdateDate = [json StringOf: @"payload.Orders[i].LastUpdateDate"]; OrderStatus = [json StringOf: @"payload.Orders[i].OrderStatus"]; FulfillmentChannel = [json StringOf: @"payload.Orders[i].FulfillmentChannel"]; SalesChannel = [json StringOf: @"payload.Orders[i].SalesChannel"]; ShipServiceLevel = [json StringOf: @"payload.Orders[i].ShipServiceLevel"]; CurrencyCode = [json StringOf: @"payload.Orders[i].OrderTotal.CurrencyCode"]; Amount = [json StringOf: @"payload.Orders[i].OrderTotal.Amount"]; NumberOfItemsShipped = [[json IntOf: @"payload.Orders[i].NumberOfItemsShipped"] intValue]; NumberOfItemsUnshipped = [[json IntOf: @"payload.Orders[i].NumberOfItemsUnshipped"] intValue]; PaymentMethod = [json StringOf: @"payload.Orders[i].PaymentMethod"]; IsReplacementOrder = [json BoolOf: @"payload.Orders[i].IsReplacementOrder"]; MarketplaceId = [json StringOf: @"payload.Orders[i].MarketplaceId"]; ShipmentServiceLevelCategory = [json StringOf: @"payload.Orders[i].ShipmentServiceLevelCategory"]; OrderType = [json StringOf: @"payload.Orders[i].OrderType"]; EarliestShipDate = [json StringOf: @"payload.Orders[i].EarliestShipDate"]; LatestShipDate = [json StringOf: @"payload.Orders[i].LatestShipDate"]; EarliestDeliveryDate = [json StringOf: @"payload.Orders[i].EarliestDeliveryDate"]; LatestDeliveryDate = [json StringOf: @"payload.Orders[i].LatestDeliveryDate"]; IsBusinessOrder = [json BoolOf: @"payload.Orders[i].IsBusinessOrder"]; IsPrime = [json BoolOf: @"payload.Orders[i].IsPrime"]; IsGlobalExpressEnabled = [json BoolOf: @"payload.Orders[i].IsGlobalExpressEnabled"]; IsPremiumOrder = [json BoolOf: @"payload.Orders[i].IsPremiumOrder"]; IsSoldByAB = [json BoolOf: @"payload.Orders[i].IsSoldByAB"]; IsIBA = [json BoolOf: @"payload.Orders[i].IsIBA"]; Name = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.Name"]; AddressLine1 = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.AddressLine1"]; City = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.City"]; StateOrRegion = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.StateOrRegion"]; PostalCode = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.PostalCode"]; CountryCode = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.CountryCode"]; Phone = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.Phone"]; AddressType = [json StringOf: @"payload.Orders[i].DefaultShipFromLocationAddress.AddressType"]; FulfillmentSupplySourceId = [json StringOf: @"payload.Orders[i].FulfillmentInstruction.FulfillmentSupplySourceId"]; IsISPU = [json BoolOf: @"payload.Orders[i].IsISPU"]; IsAccessPointOrder = [json BoolOf: @"payload.Orders[i].IsAccessPointOrder"]; HasAutomatedShippingSettings = [json BoolOf: @"payload.Orders[i].AutomatedShippingSettings.HasAutomatedShippingSettings"]; EasyShipShipmentStatus = [json StringOf: @"payload.Orders[i].EasyShipShipmentStatus"]; ElectronicInvoiceStatus = [json StringOf: @"payload.Orders[i].ElectronicInvoiceStatus"]; j = 0; count_j = [[json SizeOfArray: @"payload.Orders[i].PaymentMethodDetails"] intValue]; while (j < count_j) { json.J = [NSNumber numberWithInt: j]; strVal = [json StringOf: @"payload.Orders[i].PaymentMethodDetails[j]"]; j = j + 1; } i = i + 1; } NSLog(@"%@",@"Success!"); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.