Sample code for 30+ languages & platforms
PowerBuilder

Amazon SP-API Sellers Get Marketplace Participations

See more Amazon SP-API Examples

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

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_AuthAws
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_JsonToken
string ls_Lwa_token
oleobject loo_SbResponse
string ls_Uri
integer li_StatusCode
oleobject loo_Json
string ls_Id
string ls_CountryCode
string ls_Name
string ls_DefaultCurrencyCode
string ls_DefaultLanguageCode
string ls_DomainName
integer li_IsParticipating
integer li_HasSuspendedListings
integer i
integer li_Count_i

li_Success = 0

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

loo_AuthAws = create oleobject
li_rc = loo_AuthAws.ConnectToNewObject("Chilkat.AuthAws")
if li_rc < 0 then
    destroy loo_AuthAws
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_AuthAws.AccessKey = "AWS_ACCESS_KEY"
loo_AuthAws.SecretKey = "AWS_SECRET_KEY"
loo_AuthAws.ServiceName = "execute-api"
// Use the region that is correct for your needs.
loo_AuthAws.Region = "eu-west-1"

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")

li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
// Make sure to use the correct domain.
// In this example, we are using "sandbox.sellingpartnerapi-eu.amazon.com"
li_Success = loo_Rest.Connect("sandbox.sellingpartnerapi-eu.amazon.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_AuthAws
    destroy loo_Rest
    return
end if

li_Success = loo_Rest.SetAuthAws(loo_AuthAws)

// Load the previously obtained LWA access token.
// See Fetch SP-API LWA Access Token
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_JsonToken.LoadFile("qa_data/tokens/sp_api_lwa_token.json")
if li_Success = 0 then
    Write-Debug "Failed to load LWA access token."
    destroy loo_AuthAws
    destroy loo_Rest
    destroy loo_JsonToken
    return
end if

// Add the x-amz-access-token request header.
ls_Lwa_token = loo_JsonToken.StringOf("access_token")
loo_Rest.ClearAllHeaders()
loo_Rest.AddHeader("x-amz-access-token",ls_Lwa_token)

loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat.StringBuilder")

ls_Uri = "/sellers/v1/marketplaceParticipations"
li_Success = loo_Rest.FullRequestNoBodySb("GET",ls_Uri,loo_SbResponse)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_AuthAws
    destroy loo_Rest
    destroy loo_JsonToken
    destroy loo_SbResponse
    return
end if

// Examine the response status.
li_StatusCode = loo_Rest.ResponseStatusCode
if li_StatusCode <> 200 then
    Write-Debug "Response status text: " + loo_Rest.ResponseStatusText
    Write-Debug "Response body: "
    Write-Debug loo_SbResponse.GetAsString()
    Write-Debug "Failed."
    destroy loo_AuthAws
    destroy loo_Rest
    destroy loo_JsonToken
    destroy loo_SbResponse
    return
end if

Write-Debug loo_SbResponse.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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.LoadSb(loo_SbResponse)

i = 0
li_Count_i = loo_Json.SizeOfArray("payload")
do while i < li_Count_i
    loo_Json.I = i
    ls_Id = loo_Json.StringOf("payload[i].marketplace.id")
    ls_CountryCode = loo_Json.StringOf("payload[i].marketplace.countryCode")
    ls_Name = loo_Json.StringOf("payload[i].marketplace.name")
    ls_DefaultCurrencyCode = loo_Json.StringOf("payload[i].marketplace.defaultCurrencyCode")
    ls_DefaultLanguageCode = loo_Json.StringOf("payload[i].marketplace.defaultLanguageCode")
    ls_DomainName = loo_Json.StringOf("payload[i].marketplace.domainName")
    li_IsParticipating = loo_Json.BoolOf("payload[i].participation.isParticipating")
    li_HasSuspendedListings = loo_Json.BoolOf("payload[i].participation.hasSuspendedListings")
    i = i + 1
loop

Write-Debug "Success!"


destroy loo_AuthAws
destroy loo_Rest
destroy loo_JsonToken
destroy loo_SbResponse
destroy loo_Json