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 Create FeedSee more Amazon SP-API ExamplesCreates a feed. Amazon returns a feedDocumentId value, encryption details, and a URL for uploading the feed contents. For more information, see https://developer-docs.amazon.com/sp-api/docs/feeds-api-v2020-09-04-use-case-guide
#include <C_CkAuthAwsW.h> #include <C_CkRestW.h> #include <C_CkJsonObjectW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkAuthAwsW authAws; HCkRestW rest; BOOL success; HCkJsonObjectW jsonToken; const wchar_t *lwa_token; HCkJsonObjectW jsonReq; HCkStringBuilderW sbRequest; HCkStringBuilderW sbResponse; const wchar_t *path; int statusCode; HCkJsonObjectW json; const wchar_t *feedDocumentId; const wchar_t *url; // 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(); success = CkRestW_Connect(rest,L"sellingpartnerapi-eu.amazon.com",443,TRUE,TRUE); 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"); jsonReq = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(jsonReq,L"contentType",L"text/tab-separated-values; charset=UTF-8"); sbRequest = CkStringBuilderW_Create(); CkJsonObjectW_EmitSb(jsonReq,sbRequest); CkRestW_ClearAllQueryParams(rest); CkRestW_ClearAllHeaders(rest); CkRestW_AddHeader(rest,L"x-amz-access-token",lwa_token); sbResponse = CkStringBuilderW_Create(); path = L"/feeds/2021-06-30/documents"; success = CkRestW_FullRequestSb(rest,L"POST",path,sbRequest,sbResponse); if (success == FALSE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(jsonReq); CkStringBuilderW_Dispose(sbRequest); CkStringBuilderW_Dispose(sbResponse); return; } // Examine the response status. statusCode = CkRestW_getResponseStatusCode(rest); wprintf(L"statusCode: %d\n",statusCode); if (statusCode != 201) { 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); CkJsonObjectW_Dispose(jsonReq); CkStringBuilderW_Dispose(sbRequest); CkStringBuilderW_Dispose(sbResponse); return; } wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponse)); // If successful, gets a JSON response such as the following: // { // "feedDocumentId": "3d4e42b5-1d6e-44e8-a89c-2abfca0625bb", // "url": "https://d34o8swod1owfl.cloudfront.net/Feed_101__POST_PRODUCT_DATA_.xml" // } // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON json = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(json,sbResponse); feedDocumentId = CkJsonObjectW_stringOf(json,L"feedDocumentId"); url = CkJsonObjectW_stringOf(json,L"url"); // Save the JSON to a file for the example that constructs the XML feed and uploads.. success = CkJsonObjectW_WriteFile(json,L"qa_data/json/sp_api_feed_upload_info.json"); wprintf(L"Success!\n"); CkAuthAwsW_Dispose(authAws); CkRestW_Dispose(rest); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(jsonReq); CkStringBuilderW_Dispose(sbRequest); CkStringBuilderW_Dispose(sbResponse); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.