Sample code for 30+ languages & platforms
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

Unicode C++
#include <CkAuthAwsW.h>
#include <CkRestW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(L"AWS_SECRET_KEY");
    authAws.put_ServiceName(L"execute-api");
    // Use the region that is correct for your needs.
    authAws.put_Region(L"eu-west-1");

    CkRestW rest;
    success = rest.Connect(L"sandbox.sellingpartnerapi-eu.amazon.com",443,true,true);
    if (success == false) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    success = rest.SetAuthAws(authAws);

    // Load the previously obtained LWA access token.
    // See Fetch SP-API LWA Access Token
    CkJsonObjectW jsonToken;
    success = jsonToken.LoadFile(L"qa_data/tokens/sp_api_lwa_token.json");
    if (success == false) {
        wprintf(L"Failed to load LWA access token.\n");
        return;
    }

    // Add the x-amz-access-token request header.
    const wchar_t *lwa_token = jsonToken.stringOf(L"access_token");

    rest.ClearAllHeaders();
    rest.AddHeader(L"x-amz-access-token",lwa_token);

    rest.ClearAllQueryParams();
    rest.AddQueryParam(L"feedTypes",L"POST_PRODUCT_DATA");
    rest.AddQueryParam(L"pageSize",L"10");
    rest.AddQueryParam(L"processingStatuses",L"CANCELLED,DONE");

    CkStringBuilderW sbResponse;
    const wchar_t *path = L"/feeds/2021-06-30/feeds";
    success = rest.FullRequestNoBodySb(L"GET",path,sbResponse);
    if (success == false) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    // Examine the response status.
    int statusCode = rest.get_ResponseStatusCode();
    if (statusCode != 200) {
        wprintf(L"Response status text: %s\n",rest.responseStatusText());
        wprintf(L"Response body: \n");
        wprintf(L"%s\n",sbResponse.getAsString());
        wprintf(L"Failed.\n");
        return;
    }

    wprintf(L"%s\n",sbResponse.getAsString());

    // 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

    CkJsonObjectW json;

    json.LoadSb(sbResponse);

    const wchar_t *feedId = 0;
    const wchar_t *feedType = 0;
    const wchar_t *createdTime = 0;
    const wchar_t *processingStatus = 0;
    const wchar_t *processingStartTime = 0;
    const wchar_t *processingEndTime = 0;

    const wchar_t *nextToken = json.stringOf(L"nextToken");
    int i = 0;
    int count_i = json.SizeOfArray(L"feeds");
    while (i < count_i) {
        json.put_I(i);
        feedId = json.stringOf(L"feeds[i].feedId");
        feedType = json.stringOf(L"feeds[i].feedType");
        createdTime = json.stringOf(L"feeds[i].createdTime");
        processingStatus = json.stringOf(L"feeds[i].processingStatus");
        processingStartTime = json.stringOf(L"feeds[i].processingStartTime");
        processingEndTime = json.stringOf(L"feeds[i].processingEndTime");
        i = i + 1;
    }

    wprintf(L"Success!\n");
    }