Hub per sviluppatoriStato dell'APISupporto

Tutorial: prova gli endpoint delle API dei partner di vendita

Usa la sandbox per effettuare chiamate di test senza influire sui dati di produzione.

Selling Partner API (SP-API) provides sandbox environments where you can test the SP-API endpoints without affecting production data. You can direct calls to the SP-API sandbox endpoints to make static requests that return mock responses. By using the sandbox, you can practice the steps required to make a call, gain an understanding of the request and response formats, practice validating application credentials, and play with API endpoints without impacting production data.

Tutorial

Il seguente tutorial dimostra come generare i token di accesso richiesti ed effettuare chiamate agli endpoint sandbox SP-API.

Prerequisiti

Per completare questo tutorial, sono necessari i seguenti prerequisiti:

  • A Postman account and workspace. For more information on how to use Postman, refer to Using Postman for Selling Partner API models.
  • If you have your own selling partner account, you can self authorize your application to access your account information.
  • If you don’t have your own selling partner account, then you must set up a third-party OAuth workflow. With this workflow, third-party sellers and vendors can authorize your application to access their Amazon Selling Partner data.

Durante questo processo, riceverai un token di aggiornamento che potrai successivamente scambiare con un token di accesso. È necessario un token di accesso per chiamare gli endpoint SP-API.

Variabili necessarie per eseguire i test con Postman

Per effettuare chiamate con Postman, devi prima configurare le credenziali. Avrai bisogno delle seguenti variabili globali per il tuo spazio di lavoro:

Flusso di lavoro dettagliato

Puoi utilizzare i seguenti passaggi per testare un endpoint dell'API Selling Partner:

Fase 1. Genera un token di accesso Login with Amazon (LWA)

Per prima cosa devi autorizzare la tua applicazione ad accedere ai dati di vendita per conto di un partner di vendita. Quando si genera un token di accesso Login with Amazon (LWA), questo può essere utilizzato per più chiamate SP-API fino alla scadenza.

For detailed steps, refer to Generate an LWA Access Token using Postman or Step 1. Request a Login with Amazon access token.

The response returns an LWA access token that you can use to authenticate your SP-API call. An LWA access token must be included in calls to all operations (except restricted operations) that return Personally Identifiable Information (PII). When calling restricted operations, you include a Restricted Access Token (RDT) instead of an LWA access token

L'immagine seguente mostra un esempio di avvio del token di accesso Atza|**************************** e scade tra (il numero di secondi prima che il token di accesso LWA diventi non valido) 3600 secondi (1 ora).

2034

Richiesta e risposta del token di accesso LWA

Fase 2 Effettuare una chiamata all'endpoint sandbox SP-API

I passaggi seguenti spiegano come esercitarsi a effettuare una chiamata all'endpoint sandbox SP-API utilizzando il modello Orders API Swagger. È possibile utilizzare questo processo per testare le chiamate API ed esaminare richieste e risposte fittizie.

  1. Import the Orders API Swagger model to your Postman workspace.
  2. Cerca nel codice un x-amzn-api-sandbox oggetto che contiene un array statico di esempi di richieste e risposte per chiamate sandbox statiche all'operazione API in cui appaiono.
  3. Imposta i parametri della richiesta con gli stessi valori definiti dal modello Orders API Swagger.
  4. Verifica che la tua richiesta includa tutti i parametri richiesti definiti nel modello Swagger corrispondente. L'esempio seguente mostra un Ordina API v0 Modello Swagger, dove Get Order La chiamata API viene evidenziata con una risposta corretta:
2148

API per gli ordini v0, modello Swagger

  1. Crea un GET Chiama a /orders/v0/orders.
  2. Set the baseUrl as Selling Partner API sandbox.
  3. Sotto il Parametri scheda, passa i valori di richiesta statici dal modello Orders API.
2704

Valori di richiesta statici nella scheda Params

  1. Under the Headers tab, pass the access_token received in Step 1 for each API call, using the key value pair x-amz-access-token: Atc|********************. Skip this step for restricted operations and grantless operations.
2720

Token di accesso nella scheda Headers

  1. For restricted operations, pass the Restricted Data Token (RDT) received from the createRestrictedDataToken operations using the key value pair x-amz-access-token: Atz.sprdt|********************.

🚧

Importante

If you are calling a restricted operation to access a customer's Personally Identifiable Information (PII), such as buyer information or a shipping address, pass a Restricted Data Token (RDT) in the request headers instead of an LWA access token. You can call the createRestrictedDataToken operation in Tokens API to get a Restricted Data Token (RDT) for one or more restricted resources that you specify.

Il seguente esempio di risposta restituisce un RDT e la relativa ora di scadenza. Il token RDT può essere utilizzato in Get Orders operazione per recuperare dati PII.

2708

Tempo di risposta e scadenza del Data Token con restrizioni

{ "restrictedDataToken": "Atz.sprdt|IQEBLjAsAhRmHjNgHpi0U-Dme37rR6CuUpSR", "expiresIn": 3600 }

  1. Verifica che la risposta restituisca un payload che corrisponda al modello Swagger.
2698

Ottieni la risposta statica dell'API Orders v0 utilizzando il token di accesso

Usa la sandbox dinamica dell'API Selling Partner per effettuare richieste con stato

The SP-API also provides a dynamic sandbox where you can make requests and receive varied responses that are potentially stateful and that react to input.

Puoi determinare quali operazioni supportano le chiamate sandbox dinamiche esaminando il JSON del modello Swagger per l'API che desideri chiamare. Un'operazione supporta le chiamate alla sandbox dinamica se l'operazione include il seguente oggetto:

"x-amzn-api-sandbox": { "dynamic": {} }

L'oggetto può essere trovato a livello di operazione o di percorso. A livello di percorso, tutte le operazioni all'interno del percorso possono effettuare chiamate alla sandbox dinamica.

For more details on how to make calls to the dynamic sandbox, refer to How to make a dynamic sandbox call to the Selling Partner API.

Conclusione

In questo tutorial, hai imparato a testare i tuoi endpoint sandbox SP-API. Nella procedura dettagliata, avete generato un token di accesso LWA ed esplorato esempi di chiamate SP-API agli endpoint sandbox.


Questa pagina ti è stata utile?