Unicode C
Unicode C
Amazon SP-API Get Feeds
See more Amazon SP-API Examples
Returns feed details for the feeds that match the filters that you specify.Chilkat Unicode C Downloads
#include <C_CkAuthAwsW.h>
#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkAuthAwsW authAws;
HCkRestW rest;
HCkJsonObjectW jsonToken;
const wchar_t *lwa_token;
HCkStringBuilderW sbResponse;
const wchar_t *path;
int statusCode;
HCkJsonObjectW json;
const wchar_t *feedId;
const wchar_t *feedType;
const wchar_t *createdTime;
const wchar_t *processingStatus;
const wchar_t *processingStartTime;
const wchar_t *processingEndTime;
const wchar_t *nextToken;
int i;
int count_i;
success = FALSE;
// 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"sandbox.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");
CkRestW_ClearAllHeaders(rest);
CkRestW_AddHeader(rest,L"x-amz-access-token",lwa_token);
CkRestW_ClearAllQueryParams(rest);
CkRestW_AddQueryParam(rest,L"feedTypes",L"POST_PRODUCT_DATA");
CkRestW_AddQueryParam(rest,L"pageSize",L"10");
CkRestW_AddQueryParam(rest,L"processingStatuses",L"CANCELLED,DONE");
sbResponse = CkStringBuilderW_Create();
path = L"/feeds/2021-06-30/feeds";
success = CkRestW_FullRequestNoBodySb(rest,L"GET",path,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:
// {
// "feeds": [
// {
// "feedId": "FeedId1",
// "feedType": "POST_PRODUCT_DATA",
// "createdTime": "2019-12-11T13:16:24.630Z",
// "processingStatus": "CANCELLED",
// "processingStartTime": "2019-12-11T13:16:24.630Z",
// "processingEndTime": "2019-12-11T13:16:24.630Z"
// }
// ],
// "nextToken": "VGhpcyB0b2tlbiBpcyBvcGFxdWUgYW5kIGludGVudGlvbmFsbHkgb2JmdXNjYXRlZA=="
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
json = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(json,sbResponse);
nextToken = CkJsonObjectW_stringOf(json,L"nextToken");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(json,L"feeds");
while (i < count_i) {
CkJsonObjectW_putI(json,i);
feedId = CkJsonObjectW_stringOf(json,L"feeds[i].feedId");
feedType = CkJsonObjectW_stringOf(json,L"feeds[i].feedType");
createdTime = CkJsonObjectW_stringOf(json,L"feeds[i].createdTime");
processingStatus = CkJsonObjectW_stringOf(json,L"feeds[i].processingStatus");
processingStartTime = CkJsonObjectW_stringOf(json,L"feeds[i].processingStartTime");
processingEndTime = CkJsonObjectW_stringOf(json,L"feeds[i].processingEndTime");
i = i + 1;
}
wprintf(L"Success!\n");
CkAuthAwsW_Dispose(authAws);
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(jsonToken);
CkStringBuilderW_Dispose(sbResponse);
CkJsonObjectW_Dispose(json);
}