Sample code for 30+ languages & platforms
Unicode C++

Amazon SP-API Create Feed Doc

See more Amazon SP-API Examples

Creates a feed document. Amazon returns a feedDocumentId value, encryption details, and a URL for uploading the feed contents.

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"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");

    CkJsonObjectW jsonReq;
    jsonReq.UpdateString(L"contentType",L"text/tab-separated-values; charset=UTF-8");

    CkStringBuilderW sbRequest;
    jsonReq.EmitSb(sbRequest);

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

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

    // Examine the response status.
    int statusCode = rest.get_ResponseStatusCode();
    wprintf(L"statusCode: %d\n",statusCode);

    if (statusCode != 201) {
        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:

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

    CkJsonObjectW json;

    json.LoadSb(sbResponse);

    const wchar_t *feedDocumentId = json.stringOf(L"feedDocumentId");
    const wchar_t *url = json.stringOf(L"url");

    // Save the JSON to a file for the example that uploads the feed..
    success = json.WriteFile(L"qa_data/json/sp_api_feed_upload_info.json");

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