Sample code for 30+ languages & platforms
Tcl

Amazon SP-API Sellers Get Marketplace Participations

See more Amazon SP-API Examples

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

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "AWS_SECRET_KEY"
CkAuthAws_put_ServiceName $authAws "execute-api"
# Use the region that is correct for your needs.
CkAuthAws_put_Region $authAws "eu-west-1"

set rest [new_CkRest]

set bTls 1
set port 443
set bAutoReconnect 1
# Make sure to use the correct domain.
# In this example, we are using "sandbox.sellingpartnerapi-eu.amazon.com"
set success [CkRest_Connect $rest "sandbox.sellingpartnerapi-eu.amazon.com" $port $bTls $bAutoReconnect]
if {$success == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkAuthAws $authAws
    delete_CkRest $rest
    exit
}

set success [CkRest_SetAuthAws $rest $authAws]

# Load the previously obtained LWA access token.
# See Fetch SP-API LWA Access Token
set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/sp_api_lwa_token.json"]
if {$success == 0} then {
    puts "Failed to load LWA access token."
    delete_CkAuthAws $authAws
    delete_CkRest $rest
    delete_CkJsonObject $jsonToken
    exit
}

# Add the x-amz-access-token request header.
set lwa_token [CkJsonObject_stringOf $jsonToken "access_token"]
CkRest_ClearAllHeaders $rest
CkRest_AddHeader $rest "x-amz-access-token" $lwa_token

set sbResponse [new_CkStringBuilder]

set uri "/sellers/v1/marketplaceParticipations"
set success [CkRest_FullRequestNoBodySb $rest "GET" $uri $sbResponse]
if {$success == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkAuthAws $authAws
    delete_CkRest $rest
    delete_CkJsonObject $jsonToken
    delete_CkStringBuilder $sbResponse
    exit
}

# Examine the response status.
set statusCode [CkRest_get_ResponseStatusCode $rest]
if {$statusCode != 200} then {
    puts "Response status text: [CkRest_responseStatusText $rest]"
    puts "Response body: "
    puts [CkStringBuilder_getAsString $sbResponse]
    puts "Failed."
    delete_CkAuthAws $authAws
    delete_CkRest $rest
    delete_CkJsonObject $jsonToken
    delete_CkStringBuilder $sbResponse
    exit
}

puts [CkStringBuilder_getAsString $sbResponse]

# 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

set json [new_CkJsonObject]

CkJsonObject_LoadSb $json $sbResponse

set i 0
set count_i [CkJsonObject_SizeOfArray $json "payload"]
while {$i < $count_i} {
    CkJsonObject_put_I $json $i
    set Id [CkJsonObject_stringOf $json "payload[i].marketplace.id"]
    set CountryCode [CkJsonObject_stringOf $json "payload[i].marketplace.countryCode"]
    set Name [CkJsonObject_stringOf $json "payload[i].marketplace.name"]
    set DefaultCurrencyCode [CkJsonObject_stringOf $json "payload[i].marketplace.defaultCurrencyCode"]
    set DefaultLanguageCode [CkJsonObject_stringOf $json "payload[i].marketplace.defaultLanguageCode"]
    set DomainName [CkJsonObject_stringOf $json "payload[i].marketplace.domainName"]
    set IsParticipating [CkJsonObject_BoolOf $json "payload[i].participation.isParticipating"]
    set HasSuspendedListings [CkJsonObject_BoolOf $json "payload[i].participation.hasSuspendedListings"]
    set i [expr $i + 1]
}

puts "Success!"

delete_CkAuthAws $authAws
delete_CkRest $rest
delete_CkJsonObject $jsonToken
delete_CkStringBuilder $sbResponse
delete_CkJsonObject $json