Sample code for 30+ languages & platforms
Lua

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 Lua Downloads

Lua
local chilkat = require("chilkat")

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

local authAws = chilkat.AuthAws.new()
authAws.access_key = "AWS_ACCESS_KEY"
authAws.secret_key = "AWS_SECRET_KEY"
authAws.service_name = "execute-api"
-- Use the region that is correct for your needs.
authAws.region = "eu-west-1"

local rest = chilkat.Rest.new()
local success = rest:connect("sellingpartnerapi-eu.amazon.com", 443, true, true)
if not success then
    print(rest.last_error_text)
    return
end

success = rest:set_auth_aws(authAws)

-- Load the previously obtained LWA access token.
-- See Fetch SP-API LWA Access Token
local jsonToken = chilkat.JsonObject.new()
success = jsonToken:load_file("qa_data/tokens/sp_api_lwa_token.json")
if not success then
    print("Failed to load LWA access token.")
    return
end

-- Add the x-amz-access-token request header.
local lwa_token = jsonToken:string_of("access_token")

local jsonReq = chilkat.JsonObject.new()
jsonReq:update_string("contentType", "text/tab-separated-values; charset=UTF-8")

local sbRequest = chilkat.StringBuilder.new()
jsonReq:emit_sb(sbRequest)

rest:clear_all_query_params()
rest:clear_all_headers()
rest:add_header("x-amz-access-token", lwa_token)

local sbResponse = chilkat.StringBuilder.new()
local path = "/feeds/2021-06-30/documents"
success = rest:full_request_sb("POST", path, sbRequest, sbResponse)
if not success then
    print(rest.last_error_text)
    return
end

-- Examine the response status.
local statusCode = rest.response_status_code
print("statusCode: " .. statusCode)

if statusCode ~= 201 then
    print("Response status text: " .. rest.response_status_text)
    print("Response body: ")
    print(sbResponse:get_as_string())
    print("Failed.")
    return
end

print(sbResponse:get_as_string())

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

local json = chilkat.JsonObject.new()

json:load_sb(sbResponse)

local feedDocumentId = json:string_of("feedDocumentId")
local url = json:string_of("url")

-- Save the JSON to a file for the example that uploads the feed..
success = json:write_file("qa_data/json/sp_api_feed_upload_info.json")

print("Success!")