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 Sellers Get Marketplace ParticipationsSee more Amazon SP-API ExamplesDemonstrates Amazon SP-API Sellers API -- get marketplace participations. For more information, see https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference#getmarketplaceparticipations
#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 *lwa_token; HCkStringBuilderW sbResponse; const wchar_t *uri; int statusCode; HCkJsonObjectW json; const wchar_t *Id; const wchar_t *CountryCode; const wchar_t *Name; const wchar_t *DefaultCurrencyCode; const wchar_t *DefaultLanguageCode; const wchar_t *DomainName; BOOL IsParticipating; BOOL HasSuspendedListings; int i; int count_i; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. 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. // In this example, we are using "sandbox.sellingpartnerapi-eu.amazon.com" 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); // Load the previously obtained LWA access token. // See Fetch SP-API LWA Access Token jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/sp_api_lwa_token.json"); if (success == FALSE) { wprintf(L"Failed to load LWA access token.\n"); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); return; } // Add the x-amz-access-token request header. lwa_token = CkJsonObjectW_stringOf(jsonToken,L"access_token"); CkRestW_ClearAllHeaders(rest); CkRestW_AddHeader(rest,L"x-amz-access-token",lwa_token); // Indicate the marketplace. Use the marketplace ID for your needs. See https://developer-docs.amazon.com/sp-api/docs/marketplace-ids CkRestW_ClearAllPathParams(rest); CkRestW_AddPathParam(rest,L"MarketplaceId",L"A1F83G8C2ARO7P"); sbResponse = CkStringBuilderW_Create(); uri = L"/sellers/v1/marketplaceParticipations"; 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": [ // { // "marketplace": { // "id": "ATVPDKIKX0DER", // "countryCode": "US", // "name": "Amazon.com", // "defaultCurrencyCode": "USD", // "defaultLanguageCode": "en_US", // "domainName": "www.amazon.com" // }, // "participation": { // "isParticipating": true, // "hasSuspendedListings": false // } // } // ] // } // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON json = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(json,sbResponse); i = 0; count_i = CkJsonObjectW_SizeOfArray(json,L"payload"); while (i < count_i) { CkJsonObjectW_putI(json,i); Id = CkJsonObjectW_stringOf(json,L"payload[i].marketplace.id"); CountryCode = CkJsonObjectW_stringOf(json,L"payload[i].marketplace.countryCode"); Name = CkJsonObjectW_stringOf(json,L"payload[i].marketplace.name"); DefaultCurrencyCode = CkJsonObjectW_stringOf(json,L"payload[i].marketplace.defaultCurrencyCode"); DefaultLanguageCode = CkJsonObjectW_stringOf(json,L"payload[i].marketplace.defaultLanguageCode"); DomainName = CkJsonObjectW_stringOf(json,L"payload[i].marketplace.domainName"); IsParticipating = CkJsonObjectW_BoolOf(json,L"payload[i].participation.isParticipating"); HasSuspendedListings = CkJsonObjectW_BoolOf(json,L"payload[i].participation.hasSuspendedListings"); 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.