Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Amazon SP-API Sellers Get Marketplace ParticipationsSee more Amazon SP-API ExamplesDemonstrates Amazon SP-API Sellers API -- get marketplace participations. For more information, see https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference#getmarketplaceparticipations
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AuthAws, Rest, JsonObject, StringBuilder; ... procedure TForm1.Button1Click(Sender: TObject); var authAws: HCkAuthAws; rest: HCkRest; bTls: Boolean; port: Integer; bAutoReconnect: Boolean; success: Boolean; jsonToken: HCkJsonObject; lwa_token: PWideChar; sbResponse: HCkStringBuilder; uri: PWideChar; statusCode: Integer; json: HCkJsonObject; Id: PWideChar; CountryCode: PWideChar; Name: PWideChar; DefaultCurrencyCode: PWideChar; DefaultLanguageCode: PWideChar; DomainName: PWideChar; IsParticipating: Boolean; HasSuspendedListings: Boolean; i: Integer; count_i: Integer; begin // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. authAws := CkAuthAws_Create(); CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY'); CkAuthAws_putSecretKey(authAws,'AWS_SECRET_KEY'); CkAuthAws_putServiceName(authAws,'execute-api'); // Use the region that is correct for your needs. CkAuthAws_putRegion(authAws,'eu-west-1'); rest := CkRest_Create(); bTls := True; port := 443; bAutoReconnect := True; // Make sure to use the correct domain. // In this example, we are using "sandbox.sellingpartnerapi-eu.amazon.com" success := CkRest_Connect(rest,'sandbox.sellingpartnerapi-eu.amazon.com',port,bTls,bAutoReconnect); if (success = False) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; success := CkRest_SetAuthAws(rest,authAws); // Load the previously obtained LWA access token. // See Fetch SP-API LWA Access Token jsonToken := CkJsonObject_Create(); success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/sp_api_lwa_token.json'); if (success = False) then begin Memo1.Lines.Add('Failed to load LWA access token.'); Exit; end; // Add the x-amz-access-token request header. lwa_token := CkJsonObject__stringOf(jsonToken,'access_token'); CkRest_ClearAllHeaders(rest); CkRest_AddHeader(rest,'x-amz-access-token',lwa_token); // Indicate the marketplace. Use the marketplace ID for your needs. See https://developer-docs.amazon.com/sp-api/docs/marketplace-ids CkRest_ClearAllPathParams(rest); CkRest_AddPathParam(rest,'MarketplaceId','A1F83G8C2ARO7P'); sbResponse := CkStringBuilder_Create(); uri := '/sellers/v1/marketplaceParticipations'; success := CkRest_FullRequestNoBodySb(rest,'GET',uri,sbResponse); if (success = False) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; // Examine the response status. statusCode := CkRest_getResponseStatusCode(rest); if (statusCode <> 200) then begin Memo1.Lines.Add('Response status text: ' + CkRest__responseStatusText(rest)); Memo1.Lines.Add('Response body: '); Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponse)); Memo1.Lines.Add('Failed.'); Exit; end; Memo1.Lines.Add(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 json := CkJsonObject_Create(); CkJsonObject_LoadSb(json,sbResponse); i := 0; count_i := CkJsonObject_SizeOfArray(json,'payload'); while i < count_i do begin CkJsonObject_putI(json,i); Id := CkJsonObject__stringOf(json,'payload[i].marketplace.id'); CountryCode := CkJsonObject__stringOf(json,'payload[i].marketplace.countryCode'); Name := CkJsonObject__stringOf(json,'payload[i].marketplace.name'); DefaultCurrencyCode := CkJsonObject__stringOf(json,'payload[i].marketplace.defaultCurrencyCode'); DefaultLanguageCode := CkJsonObject__stringOf(json,'payload[i].marketplace.defaultLanguageCode'); DomainName := CkJsonObject__stringOf(json,'payload[i].marketplace.domainName'); IsParticipating := CkJsonObject_BoolOf(json,'payload[i].participation.isParticipating'); HasSuspendedListings := CkJsonObject_BoolOf(json,'payload[i].participation.hasSuspendedListings'); i := i + 1; end; Memo1.Lines.Add('Success!'); CkAuthAws_Dispose(authAws); CkRest_Dispose(rest); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbResponse); CkJsonObject_Dispose(json); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.