Sample code for 30+ languages & platforms
Lua

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 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("sandbox.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")

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

rest:clear_all_query_params()
rest:add_query_param("feedTypes", "POST_PRODUCT_DATA")
rest:add_query_param("pageSize", "10")
rest:add_query_param("processingStatuses", "CANCELLED,DONE")

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

-- Examine the response status.
local statusCode = rest.response_status_code
if statusCode ~= 200 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:

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

local json = chilkat.JsonObject.new()

json:load_sb(sbResponse)

local feedId = ""
local feedType = ""
local createdTime = ""
local processingStatus = ""
local processingStartTime = ""
local processingEndTime = ""

local nextToken = json:string_of("nextToken")
local i = 0
local count_i = json:size_of_array("feeds")
while i < count_i do
    json.i = i
    feedId = json:string_of("feeds[i].feedId")
    feedType = json:string_of("feeds[i].feedType")
    createdTime = json:string_of("feeds[i].createdTime")
    processingStatus = json:string_of("feeds[i].processingStatus")
    processingStartTime = json:string_of("feeds[i].processingStartTime")
    processingEndTime = json:string_of("feeds[i].processingEndTime")
    i = i + 1
end

print("Success!")