Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oAuthAws
LOCAL oRest
LOCAL oJsonToken
LOCAL cLwa_token
LOCAL oJsonReq
LOCAL oSbRequest
LOCAL oSbResponse
LOCAL cPath
LOCAL nStatusCode
LOCAL oJson
LOCAL cFeedDocumentId
LOCAL cUrl

nSuccess := 0

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

oAuthAws := CreateObject("Chilkat.AuthAws")
oAuthAws:AccessKey := "AWS_ACCESS_KEY"
oAuthAws:SecretKey := "AWS_SECRET_KEY"
oAuthAws:ServiceName := "execute-api"
//  Use the region that is correct for your needs.
oAuthAws:Region := "eu-west-1"

oRest := CreateObject("Chilkat.Rest")
nSuccess := oRest:Connect("sellingpartnerapi-eu.amazon.com", 443, 1, 1)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oAuthAws:destroy()
    oRest:destroy()
    RETURN
ENDIF

nSuccess := oRest:SetAuthAws(oAuthAws)

//  Load the previously obtained LWA access token.
//  See Fetch SP-API LWA Access Token
oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/sp_api_lwa_token.json")
IF (nSuccess == 0)
    ? "Failed to load LWA access token."
    oAuthAws:destroy()
    oRest:destroy()
    oJsonToken:destroy()
    RETURN
ENDIF

//  Add the x-amz-access-token request header.
cLwa_token := oJsonToken:StringOf("access_token")

oJsonReq := CreateObject("Chilkat.JsonObject")
oJsonReq:UpdateString("contentType", "text/tab-separated-values; charset=UTF-8")

oSbRequest := CreateObject("Chilkat.StringBuilder")
oJsonReq:EmitSb(oSbRequest)

oRest:ClearAllQueryParams()
oRest:ClearAllHeaders()
oRest:AddHeader("x-amz-access-token", cLwa_token)

oSbResponse := CreateObject("Chilkat.StringBuilder")
cPath := "/feeds/2021-06-30/documents"
nSuccess := oRest:FullRequestSb("POST", cPath, oSbRequest, oSbResponse)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oAuthAws:destroy()
    oRest:destroy()
    oJsonToken:destroy()
    oJsonReq:destroy()
    oSbRequest:destroy()
    oSbResponse:destroy()
    RETURN
ENDIF

//  Examine the response status.
nStatusCode := oRest:ResponseStatusCode
? "statusCode: " + Str(nStatusCode)

IF (nStatusCode != 201)
    ? "Response status text: " + oRest:ResponseStatusText
    ? "Response body: "
    ? oSbResponse:GetAsString()
    ? "Failed."
    oAuthAws:destroy()
    oRest:destroy()
    oJsonToken:destroy()
    oJsonReq:destroy()
    oSbRequest:destroy()
    oSbResponse:destroy()
    RETURN
ENDIF

? oSbResponse: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

oJson := CreateObject("Chilkat.JsonObject")

oJson:LoadSb(oSbResponse)

cFeedDocumentId := oJson:StringOf("feedDocumentId")
cUrl := oJson:StringOf("url")

//  Save the JSON to a file for the example that uploads the feed..
nSuccess := oJson:WriteFile("qa_data/json/sp_api_feed_upload_info.json")

? "Success!"

oAuthAws:destroy()
oRest:destroy()
oJsonToken:destroy()
oJsonReq:destroy()
oSbRequest:destroy()
oSbResponse:destroy()
oJson:destroy()