Sample code for 30+ languages & platforms
Xbase++

Amazon SP-API Sellers Get Marketplace Participations

See more Amazon SP-API Examples

Demonstrates Amazon SP-API Sellers API -- get marketplace participations.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oAuthAws
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oJsonToken
LOCAL cLwa_token
LOCAL oSbResponse
LOCAL cUri
LOCAL nStatusCode
LOCAL oJson
LOCAL cId
LOCAL cCountryCode
LOCAL cName
LOCAL cDefaultCurrencyCode
LOCAL cDefaultLanguageCode
LOCAL cDomainName
LOCAL nIsParticipating
LOCAL nHasSuspendedListings
LOCAL i
LOCAL nCount_i

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")
nBTls := 1
nPort := 443
nBAutoReconnect := 1
//  Make sure to use the correct domain.
//  In this example, we are using "sandbox.sellingpartnerapi-eu.amazon.com"
nSuccess := oRest:Connect("sandbox.sellingpartnerapi-eu.amazon.com", nPort, nBTls, nBAutoReconnect)
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")
oRest:ClearAllHeaders()
oRest:AddHeader("x-amz-access-token", cLwa_token)

oSbResponse := CreateObject("Chilkat.StringBuilder")
cUri := "/sellers/v1/marketplaceParticipations"
nSuccess := oRest:FullRequestNoBodySb("GET", cUri, oSbResponse)
IF (nSuccess == 0)
    ? oRest:LastErrorText
    oAuthAws:destroy()
    oRest:destroy()
    oJsonToken:destroy()
    oSbResponse:destroy()
    RETURN
ENDIF

//  Examine the response status.
nStatusCode := oRest:ResponseStatusCode
IF (nStatusCode != 200)
    ? "Response status text: " + oRest:ResponseStatusText
    ? "Response body: "
    ? oSbResponse:GetAsString()
    ? "Failed."
    oAuthAws:destroy()
    oRest:destroy()
    oJsonToken:destroy()
    oSbResponse:destroy()
    RETURN
ENDIF

? oSbResponse:GetAsString()

//  If successful, gets a JSON response such as the following:

//  {
//    "payload": [
//      {
//        "marketplace": {
//          "id": "ATVPDKIKX0DER",
//          "countryCode": "US",
//          "name": "Amazon.com",
//          "defaultCurrencyCode": "USD",
//          "defaultLanguageCode": "en_US",
//          "domainName": "www.amazon.com"
//        },
//        "participation": {
//          "isParticipating": true,
//          "hasSuspendedListings": false
//        }
//      }
//    ]
//  }

//  Use this online tool to generate parsing code from sample JSON: 
//  Generate Parsing Code from JSON

oJson := CreateObject("Chilkat.JsonObject")

oJson:LoadSb(oSbResponse)

i := 0
nCount_i := oJson:SizeOfArray("payload")
DO WHILE i < nCount_i
    oJson:I := i
    cId := oJson:StringOf("payload[i].marketplace.id")
    cCountryCode := oJson:StringOf("payload[i].marketplace.countryCode")
    cName := oJson:StringOf("payload[i].marketplace.name")
    cDefaultCurrencyCode := oJson:StringOf("payload[i].marketplace.defaultCurrencyCode")
    cDefaultLanguageCode := oJson:StringOf("payload[i].marketplace.defaultLanguageCode")
    cDomainName := oJson:StringOf("payload[i].marketplace.domainName")
    nIsParticipating := oJson:BoolOf("payload[i].participation.isParticipating")
    nHasSuspendedListings := oJson:BoolOf("payload[i].participation.hasSuspendedListings")
    i := i + 1
ENDDO

? "Success!"

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