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
(Swift 3,4,5...) 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
func chilkatTest() { // 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" let authAws = CkoAuthAws()! 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" let rest = CkoRest()! var bTls: Bool = true var port: Int = 443 var bAutoReconnect: Bool = true // Make sure to use the correct domain. // This example is using the sandbox var success: Bool = rest.connect("sandbox.sellingpartnerapi-eu.amazon.com", port: port, tls: bTls, autoReconnect: bAutoReconnect) if success == false { print("\(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 let jsonToken = CkoJsonObject()! success = jsonToken.loadFile("qa_data/tokens/sp_api_rdt_token.json") if success == false { print("Failed to load RDT access token.") return } // Add the x-amz-access-token request header. var rdt_token: String? = jsonToken.string(of: "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") let sbResponse = CkoStringBuilder()! var uri: String? = "/orders/v0/orders" success = rest.fullRequestNoBodySb("GET", uriPath: uri, sb: sbResponse) if success == false { print("\(rest.lastErrorText!)") return } // Examine the response status. var statusCode: Int = rest.responseStatusCode.intValue if statusCode != 200 { print("Response status text: \(rest.responseStatusText!)") print("Response body: ") print("\(sbResponse.getAsString()!)") print("Failed.") return } print("\(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 let json = CkoJsonObject()! json.loadSb(sbResponse) var AmazonOrderId: String? var PurchaseDate: String? var LastUpdateDate: String? var OrderStatus: String? var FulfillmentChannel: String? var SalesChannel: String? var ShipServiceLevel: String? var CurrencyCode: String? var Amount: String? var NumberOfItemsShipped: Int var NumberOfItemsUnshipped: Int var PaymentMethod: String? var IsReplacementOrder: Bool var MarketplaceId: String? var ShipmentServiceLevelCategory: String? var OrderType: String? var EarliestShipDate: String? var LatestShipDate: String? var EarliestDeliveryDate: String? var LatestDeliveryDate: String? var IsBusinessOrder: Bool var IsPrime: Bool var IsGlobalExpressEnabled: Bool var IsPremiumOrder: Bool var IsSoldByAB: Bool var IsIBA: Bool var Name: String? var AddressLine1: String? var City: String? var StateOrRegion: String? var PostalCode: String? var CountryCode: String? var Phone: String? var AddressType: String? var FulfillmentSupplySourceId: String? var IsISPU: Bool var IsAccessPointOrder: Bool var HasAutomatedShippingSettings: Bool var EasyShipShipmentStatus: String? var ElectronicInvoiceStatus: String? var j: Int var count_j: Int var strVal: String? var CreatedBefore: String? = json.string(of: "payload.CreatedBefore") var i: Int = 0 var count_i: Int = json.size(ofArray: "payload.Orders").intValue while i < count_i { json.i = i AmazonOrderId = json.string(of: "payload.Orders[i].AmazonOrderId") PurchaseDate = json.string(of: "payload.Orders[i].PurchaseDate") LastUpdateDate = json.string(of: "payload.Orders[i].LastUpdateDate") OrderStatus = json.string(of: "payload.Orders[i].OrderStatus") FulfillmentChannel = json.string(of: "payload.Orders[i].FulfillmentChannel") SalesChannel = json.string(of: "payload.Orders[i].SalesChannel") ShipServiceLevel = json.string(of: "payload.Orders[i].ShipServiceLevel") CurrencyCode = json.string(of: "payload.Orders[i].OrderTotal.CurrencyCode") Amount = json.string(of: "payload.Orders[i].OrderTotal.Amount") NumberOfItemsShipped = json.int(of: "payload.Orders[i].NumberOfItemsShipped").intValue NumberOfItemsUnshipped = json.int(of: "payload.Orders[i].NumberOfItemsUnshipped").intValue PaymentMethod = json.string(of: "payload.Orders[i].PaymentMethod") IsReplacementOrder = json.bool(of: "payload.Orders[i].IsReplacementOrder") MarketplaceId = json.string(of: "payload.Orders[i].MarketplaceId") ShipmentServiceLevelCategory = json.string(of: "payload.Orders[i].ShipmentServiceLevelCategory") OrderType = json.string(of: "payload.Orders[i].OrderType") EarliestShipDate = json.string(of: "payload.Orders[i].EarliestShipDate") LatestShipDate = json.string(of: "payload.Orders[i].LatestShipDate") EarliestDeliveryDate = json.string(of: "payload.Orders[i].EarliestDeliveryDate") LatestDeliveryDate = json.string(of: "payload.Orders[i].LatestDeliveryDate") IsBusinessOrder = json.bool(of: "payload.Orders[i].IsBusinessOrder") IsPrime = json.bool(of: "payload.Orders[i].IsPrime") IsGlobalExpressEnabled = json.bool(of: "payload.Orders[i].IsGlobalExpressEnabled") IsPremiumOrder = json.bool(of: "payload.Orders[i].IsPremiumOrder") IsSoldByAB = json.bool(of: "payload.Orders[i].IsSoldByAB") IsIBA = json.bool(of: "payload.Orders[i].IsIBA") Name = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.Name") AddressLine1 = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.AddressLine1") City = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.City") StateOrRegion = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.StateOrRegion") PostalCode = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.PostalCode") CountryCode = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.CountryCode") Phone = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.Phone") AddressType = json.string(of: "payload.Orders[i].DefaultShipFromLocationAddress.AddressType") FulfillmentSupplySourceId = json.string(of: "payload.Orders[i].FulfillmentInstruction.FulfillmentSupplySourceId") IsISPU = json.bool(of: "payload.Orders[i].IsISPU") IsAccessPointOrder = json.bool(of: "payload.Orders[i].IsAccessPointOrder") HasAutomatedShippingSettings = json.bool(of: "payload.Orders[i].AutomatedShippingSettings.HasAutomatedShippingSettings") EasyShipShipmentStatus = json.string(of: "payload.Orders[i].EasyShipShipmentStatus") ElectronicInvoiceStatus = json.string(of: "payload.Orders[i].ElectronicInvoiceStatus") j = 0 count_j = json.size(ofArray: "payload.Orders[i].PaymentMethodDetails").intValue while j < count_j { json.j = j strVal = json.string(of: "payload.Orders[i].PaymentMethodDetails[j]") j = j + 1 } i = i + 1 } print("Success!") } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.