Sample code for 30+ languages & platforms
React Native

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 React Native Downloads

React Native
import { AuthAws, JsonObject, Rest, StringBuilder } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const authAws = new AuthAws();
  authAws.accessKey = 'AWS_ACCESS_KEY';
  authAws.secretKey = 'AWS_SECRET_KEY';
  authAws.serviceName = 'execute-api';
  // Use the region that is correct for your needs.
  authAws.region = 'eu-west-1';

  const rest = new Rest();
  try {
    await rest.connectAsync('sellingpartnerapi-eu.amazon.com', 443, true, true);
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  rest.setAuthAws(authAws);

  // Load the previously obtained LWA access token.
  // See Fetch SP-API LWA Access Token
  const jsonToken = new JsonObject();
  try {
    jsonToken.loadFile('qa_data/tokens/sp_api_lwa_token.json');
  } catch {
    console.log('Failed to load LWA access token.');
    return;
  }

  // Add the x-amz-access-token request header.
  const lwaToken = jsonToken.stringOf('access_token');

  const jsonReq = new JsonObject();
  jsonReq.updateString('contentType', 'text/tab-separated-values; charset=UTF-8');

  const sbRequest = new StringBuilder();
  jsonReq.emitSb(sbRequest);

  rest.clearAllQueryParams();
  rest.clearAllHeaders();
  rest.addHeader('x-amz-access-token', lwaToken);

  const sbResponse = new StringBuilder();
  const path = '/feeds/2021-06-30/documents';
  try {
    await rest.fullRequestSbAsync('POST', path, sbRequest, sbResponse);
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  // Examine the response status.
  const statusCode = rest.responseStatusCode;
  console.log(`statusCode: ${statusCode}`);

  if (statusCode !== 201) {
    console.log(`Response status text: ${rest.responseStatusText}`);
    console.log('Response body: ');
    console.log(sbResponse.getAsString());
    console.log('Failed.');
    return;
  }

  console.log(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

  const json = new JsonObject();

  json.loadSb(sbResponse);

  const feedDocumentId = json.stringOf('feedDocumentId');
  const url = json.stringOf('url');

  // Save the JSON to a file for the example that uploads the feed..
  json.writeFile('qa_data/json/sp_api_feed_upload_info.json');

  console.log('Success!');
}