Guide des cas d'utilisation de l'API Messagerie v1

Envoyer des messages aux acheteurs à propos de leurs commandes

Qu'est-ce que l'API Messagerie ?

The Selling Partner API for Messaging (Messaging API) allows you to create applications that enable sellers to send messages to buyers after they place an order. Sellers can send a variety of message types. These include asking order related questions, arranging a delivery, and more. The Messaging API can send messages to a buyer, even if the buyer has not contacted the seller first. However, you cannot use this API to respond to messages from buyers.

Refer to the Messaging API reference for a list of operations that correspond to the available message types.

Terminologie

Amazon S3 presigned URL: A URL for an Amazon S3 bucket to which you can upload an object without AWS security credentials or permissions. You get an Amazon S3 presigned URL in Step 7. Create an upload destination.

Disponibilité des messages

Tous les types de messages ne sont pas disponibles en toutes circonstances. Un certain nombre de facteurs peuvent affecter la disponibilité des messages, notamment le fait que la commande ait été traitée, le type de vendeur ou le nombre de messages déjà envoyés pour la commande.

Workflow pour l'envoi d'un message

Ce qui suit est destiné à l'utilisateur de l'application. L'envoi d'un message est un processus en plusieurs étapes qui inclut des appels aux opérations à la fois dans l'API de messagerie et dans l'API de téléchargement. Voici le flux de travail de base pour envoyer un message :

  1. Votre application affiche les commandes récentes du vendeur, et ce dernier choisit une commande pour laquelle
    il souhaite envoyer un message à l'acheteur.

  2. Your application displays the message types that are available for the order that the seller chooses. Get the available message types by calling the getMessagingActionsForOrder operation of the Messaging API.

  3. Le vendeur choisit un type de message pour la commande.

  4. Si les messages personnalisés sont pris en charge pour le type de message, le vendeur peut saisir un message personnalisé.

  5. Si les pièces jointes sont prises en charge pour le type de message, le vendeur peut charger une pièce jointe dans votre application. Le vendeur peut également saisir un nom de fichier pour la pièce jointe.

  6. Si le vendeur ajoute une pièce jointe à votre application, celle-ci la charge dans un compartiment Amazon S3 en procédant comme suit :

    • Calcul d'un hachage Content-MD5 pour la pièce jointe, nécessaire pour créer une destination de chargement.

    • Création d'une destination de chargement en appelant l'opération createUploadDestination de l'API Chargements.

    • Chargement de la pièce jointe vers la destination.

  7. Votre application demande qu'un message soit envoyé par le vendeur à l'acheteur en appelant l'opération correspondant au type de message choisi par le vendeur à l'étape #3. Par exemple, votre application appelle createConfirmOrderDetails opération si le vendeur a choisi le type de message « Confirmer les détails de la commande ».

  8. Amazon emails a message from the seller to the buyer. Refer to Tutorial: Send a message for the detailed workflow.

Tutoriel : Envoyer un message

Ce tutoriel explique comment créer une application permettant à un vendeur d'envoyer un message à un acheteur.

Conditions préalables

Pour terminer ce didacticiel, vous devez :

Étape 1 : Accéder à la commande pour laquelle le vendeur souhaite envoyer un message

  1. Afficher la liste des commandes récentes du vendeur parmi lesquelles choisir.

  2. Le vendeur choisit une commande pour laquelle il souhaite envoyer un message à l'acheteur.

  3. Associer un numéro de commande Amazon à la commande choisie par le vendeur.

  4. Save the Amazon order identifier for Step 2. Get a list of available message types.

Étape 2 : Obtenir la liste des types de messages disponibles

Call the getMessagingActionsForOrder operation of the Messaging API, specifying the Amazon order identifier from
Step 1. Get the order for which the seller wants to send a message to get a list of message types that are available for the order.

  1. Call the getMessagingActionsForOrder operation of the Messaging API, passing the following parameters:

Paramètre de chemin d'accès

Paramètre Description Obligatoire
amazonOrderId An Amazon order identifier. This specifies the order for which a message is to be sent. Get this value from Step 1. Get the order for which the seller wants to send a message.

Type : chaîne

Oui

Paramètre de requête :

Paramètre Description Obligatoire
marketplaceIds Ce paramètre correspond à un identifiant de site de vente. Il indique le site de vente sur lequel la commande a été passée. Notez que vous ne pouvez spécifier qu'un seul site de vente.

Type : array[string]

Oui

Exemple de demande

GET https://sellingpartnerapi-na.amazon.com/messaging/v1/orders/902-6786204-8179805?marketplaceIds=ATVPDKIKX0DER

Réponse

Le schéma de réponse pour l'opération getMessagingActionsForOrder.

NomDescriptionSchema
_links
optional
Objet dont les noms de propriété sont des types de relations de lien et dont les valeurs sont soit un objet de lien, soit un tableau d'objets de lien. La ressource objet de ces liens est l'objet ressource, dont l'objet contenant “_links” est une propriété._links
_embedded
optional
Objet dont les noms de propriété sont des types de relation de lien et dont les valeurs sont soit un objet de ressource, soit un tableau d'objets de ressource. Les ressources intégrées peuvent être une version complète, partielle ou incohérente de la représentation fournie par l'URI cible._embedded
errors
optional
Liste des réponses d'erreur renvoyées en cas d'échec d'une demande.ErrorList

_links

NomDescriptionSchema
self
required
Correspond à la relation “self” enregistrée auprès de l'IANA dont la cible est l'URI de la ressource.LinkObject
actions
required
Ce paramètre correspond aux actions éligibles pour l'amazonOrderId spécifié.< LinkObject > array


_embedded

NomSchema
actions
required
< GetMessagingActionResponse > array

Exemple de réponse

{ "_links": { "actions": [ { "href": "/messaging/v1/orders/902-6786204- 8179805/messages/confirmCustomizationDetails?marketplaceIds=ATVPDKIKX0 DER", "name": "confirmCustomizationDetails" }, { "href": "/messaging/v1/orders/902-6786204- 8179805/messages/negativeFeedbackRemoval?marketplaceIds=ATVPDKIKX0DER" , "name": "negativeFeedbackRemoval" }, { "href": "/messaging/v1/orders/902-6786204- 8179805/messages/confirmOrderDetails?marketplaceIds=ATVPDKIKX0DER", "name": "confirmOrderDetails" }, ], "self": { "href": "/messaging/v1/orders/902-6786204- 8179805?marketplaceIds=ATVPDKIKX0DER" } }, "_embedded": { "actions": [ { "_links": { "schema": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/confirmCustomizationDetails/schema", "name": "confirmCustomizationDetails" }, "self": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/confirmCustomizationDetails?marketplaceIds=ATVPDKIKX0DER", "name": "confirmCustomizationDetails" } }, "_embedded": { "schema": { "_links": { "self": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/confirmCustomizationDetails/schema", "name": "confirmCustomizationDetails" } }, "type": "object", "name": "confirmCustomizationDetails", "title": "Confirm customization details", "description": "Ask your customer to provide details or verify the customization input provided (name spelling, imagery, initials).", "properties": { "attachments": { "type": "array", "items": { "type": "object", "required": [], "properties": { "fileName": { "type": "string" }, "id": { "type": "string" } } }, "title": "Add attachment", "description": "You can upload text files, PDFs, Word documents, and these image file types: .jpg, .gif, and .png. The total size of attachments must be less than 10 MB.", "x-ui-field-type": "attachments", "maxItems": 5 }, "rawMessageBody": { "type": "string", "title": "Explain why you are contacting and any action you need your customer to take. ", "description": "800 character limit. Only links related to order completion are allowed, no HTML or email addresses.", "x-ui-field-type": "text", "minLength": 1, "maxLength": 800 } }, "required": [ "attachments", "rawMessageBody" ], "$schema": "http://json-schema.org/draft-04/schema#", "x-ui-hidden": null } }, "name": "confirmCustomizationDetails", "title": "Confirm customization details" }, { "_links": { "schema": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/negativeFeedbackRemoval/schema", "name": "negativeFeedbackRemoval" }, "self": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/negativeFeedbackRemoval?marketplaceIds=ATVPDKIKX0DER", "name": "negativeFeedbackRemoval" } }, "_embedded": { "schema": { "_links": { "self": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/negativeFeedbackRemoval/schema", "name": "negativeFeedbackRemoval" } }, "type": "object", "name": "negativeFeedbackRemoval", "title": "Request to update negative feedback", "description": "Ask your customer to consider updating their seller feedback rating. You may only send this once per order.", "properties": {}, "required": [], "$schema": "http://json-schema.org/draft-04/schema#", "x-ui-hidden": true } }, "name": "negativeFeedbackRemoval", "title": "Request to update negative feedback" }, { "_links": { "schema": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/confirmOrderDetails/schema", "name": "confirmOrderDetails" }, "self": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/confirmOrderDetails?marketplaceIds=ATVPDKIKX0DER", "name": "confirmOrderDetails" } }, "_embedded": { "schema": { "_links": { "self": { "href": "/messaging/v1/orders/902-6786204-8179805/messages/confirmOrderDetails/schema", "name": "confirmOrderDetails" } }, "type": "object", "name": "confirmOrderDetails", "title": "Confirm order details", "description": "Ask your customer a specific order-related question prior to shipping their order.", "properties": { "rawMessageBody": { "type": "string", "title": "Explain why you are contacting and any action you need your customer to take. ", "description": "2000 character limit. Only links related to order completion are allowed, no HTML or email addresses.", "x-ui-field-type": "text", "minLength": 1, "maxLength": 2000 } }, "required": [ "rawMessageBody" ], "$schema": "http://json-schema.org/draft-04/schema#", "x-ui-hidden": null } }, "name": "confirmOrderDetails", "title": "Confirm order details" }, ] } }
  1. Save the list of schemas in the _embedded.actions array of the response. In the _embedded.schema section of each array element you can find a schema for each available message type. Use the title value in each schema to create a list of available message types for the seller to choose from in Step 3. Get the seller's choice of message type. Use the schemas to understand how to display and enforce the restrictions for custom messages and attachments that apply for each message type. For more information, refer to Step 4. Get custom message text from the seller (if supported) and Step 5. Get an attachment from the seller (if supported).

  2. Save the list of paths in the _links.actions array of the response. The href value in each array element contains a path for each available message type. You can use one of these paths in a call for the appropriate operation in Step 9. Send a message to the buyer.

Étape 3 : Accéder au type de message choisi par le vendeur

  1. Display a list of available message types for the seller to choose from. Get these from the title values that you saved in Step 2. Get a list of available message types.

  2. Laissez le vendeur choisir le type de message qu'il souhaite envoyer et enregistrez-le. Ce choix aura une incidence sur plusieurs étapes ultérieures, notamment :

Étape 4 : Obtenir un texte de message personnalisé du vendeur (si la fonctionnalité est prise en charge)

Certains types de messages permettent au vendeur d'inclure un message personnalisé dans l'e-mail envoyé à l'acheteur. Pour savoir si un type de message prend en charge les messages personnalisés, consultez la référence de l’API Messagerie afin de déterminer quelle opération correspond au type de message. Par exemple, l'opération createConfirmServiceDetails correspond au type de message “Contacter le client du service à domicile”. Si l'opération inclut un paramètre de corps de texte, le type de message prend en charge les messages personnalisés.

  1. Determine if the message type that the seller chose in Step 3. Get the seller's choice of message type supports custom messages. If custom messages are not supported, go directly to Step 5. Get an attachment from the seller (if supported). If custom messages are supported, continue with this procedure.

  2. Laissez le vendeur saisir le texte brut qu'il souhaite pour son message personnalisé.

  3. Display and enforce any restrictions on the message text that the seller inputs. You can find the text restrictions in the _embedded.schema.properties.rawMessageBody section of the _embedded.actions array element that corresponds to the seller's message type. Find this in the response for the getMessagingActionsForOrder operation in Step 2. Get a list of available message types.

  4. Save the message text and use it as input for Step 9. Send a message to the buyer.

Étape 5 : Obtenir une pièce jointe du vendeur (si la fonctionnalité est prise en charge)

Certains types de messages permettent au vendeur d'inclure un lien vers une pièce jointe dans l'e-mail envoyé à l'acheteur. Pour savoir si un type de message prend en charge les pièces jointes, consultez la référence de l’API Messagerie afin de déterminer quelle opération correspond au type de message. Par exemple, l'opération createWarranty correspond au type de message “Envoyer les informations de garantie”. Si l'opération inclut un paramètre de corps de pièce jointe, le type de message prend en charge les pièces jointes.

  1. Determine if the message type that the seller chose in Step 3. Get the seller's choice of message type supports attachments. If attachments are not supported, go directly to Step 9. Send a message to the buyer. If attachments are supported, continue with this procedure.

  2. Laissez le vendeur ajouter une pièce jointe à votre application.

  3. Display and enforce any restrictions on the attachment that the seller uploads. You can find the attachment restrictions in the _embedded.schema.properties.attachments section of the _embedded.actions array element that corresponds to the seller's message type. Find this in the response for the getMessagingActionsForOrder operation in Step 2. Get a list of available message types.

  4. Convert the attachment into an input stream and save it for Step 8. Upload the attachment.

  5. Laissez le vendeur saisir un nom de fichier pour la pièce jointe, y compris l'extension du fichier.

  6. Save the file name and use it as input for Step 9. Send a message to the buyer.

Étape 6 : Calculer un hachage Content-MD5

Calculate a Content-MD5 hash for the attachment from Step 5. Get an attachment from the seller(if supported). You will need it to create an upload destination in Step 7. Create an upload destination.

L'exemple de code Java de cette étape applique une logique permettant de calculer un hachage Content-MD5 et utilise le client HTTP Apache.

  1. Utilisez ce qui suit comme entrée pour l'exemple de code :

The attachment input stream from Step 5. Get an attachment from the seller (if supported), is the argument for the fis parameter of the computeContentMD5Value method of the CreateMD5 class.

  1. Save the md5Content value to pass in with the Content-MD5 parameter in Step 7. Create an upload destination.

Exemple de code Java

package io.swagger.client.util; import java.io.FileInputStream; import java.io.IOException; import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class CreateMD5 { public static String computeContentMD5Value(FileInputStream fis) throws IOException, NoSuchAlgorithmException { DigestInputStream dis = new DigestInputStream(fis, MessageDigest.getInstance("MD5")); byte[]buffer = new byte[8192]; while (dis.read(buffer) > 0); String md5Content = new String(org.apache.commons.codec.binary.Base64 .encodeBase64(dis.getMessageDigest().digest())); // Effectively resets the stream to be beginning of the file // via a FileChannel. fis.getChannel().position(0); return md5Content; } }

Étape 7 : Créer une destination de chargement

Call the createUploadDestination operation of the Uploads API to create an upload destination for your attachment, in the form of an Amazon S3 presigned URL. For definitions, refer to Terminology.

  1. Call the createUploadDestination operation of the Uploads API, passing the following parameters:

Paramètres de requête :

TypeNomDescriptionSchema
QuerymarketplaceIds
required
Liste des identifiants de la place de marché. Cela indique les sites de vente sur lesquels le téléchargement sera disponible. Un seul site de vente peut être spécifié.
Nombre maximum : 1
< chaîne > gamme
QueryContenu MD5
required
The Content-MD5 hash that you calculated in Step 6. Calculate a Content MD5 hash.string
Pathressource
required
Ressource correspondant à la destination de téléchargement que vous êtes en train de créer. Par exemple, si vous créez une destination de téléchargement pour l'opération CreateLegalDisclosure de l'API de messagerie, {resource} serait /messaging/v1/orders/{amazonOrderId}/messages/legalDisclosure, et le chemin complet serait /uploads/2020-11-01/uploadDestinations/messaging/v1/orders/{amazonOrderId}/messages/legalDisclosure. Si vous créez une destination de téléchargement pour un document de contenu Aplus, {resource} serait aplus/2020-11-01/contentDocuments et le chemin serait /uploads/v1/uploadDestinations/aplus/2020-11-01/contentDocuments.string
QueryType de contenu
optional
Type de contenu du fichier à charger.string

Exemple de demande

POST https://sellingpartnerapi-na.amazon.com/uploads/2020-11-01/uploadDestinations/messaging/v1/orders/7XX-5XXXXX-8XXXXXX/messages/invoice?marketplaceIds=A2Q3Y263D00KWC&contentMD5=qCcR3o%2BU0FUR1%2BgXhApNfQ%3D%3D

Réponse

Le schéma de réponse pour l'opération createUploadDestination.

NomDescriptionSchema
payload
optional
Informations relatives à une destination de chargement.UploadDestination
errors
optional
Liste des réponses d'erreur renvoyées en cas d'échec d'une demande.ErrorList

Exemple de réponse

{ "payload": { "uploadDestinationId": "sc/7ae2d3b1-fdd3-42c4-98c4-9cc509fb95d8.png", "url": "https://aplus-media.s3.amazonaws.com/?x-amz-date=20201116T184623Z&x-amz-signature=c5c8efd95d883b6787a2b1a93c7c066f01cb4e8d7be3ece4360aa800332e0cf9&x-amz-meta-owner=A2CZ04NGKYDXDV&acl=private&key=sc/7ae2d3b1-fdd3-42c4-98c4-9cc509fb95d8.png&x-amz-algorithm=AWS4-HMAC-SHA256&policy=eyJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJhcGx1cy1tZWRpYS1iZXRhIn0seyJrZXkiOiJzb3RhLzdhZTJkM2IxLWZkZDMtNDJjNC05OGM0LTljYzUwOWZiOTVkOC5wbmcifSx7ImFjbCI6InByaXZhdGUifSx7IngtYW16LW1ldGEtb3duZXIiOiJBMkNaMDROR0tZRFhEViJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUE2TDZSN1FFNTZGNkdNRzVFLzIwMjAxMTE2L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWRhdGUiOiIyMDIwMTExNlQxODQ2MjNaIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMSwzMTQ1NzI4XV0sImV4cGlyYXRpb24iOiIyMDIwLTExLTE2VDIxOjQ2OjIzLjg2OFoifQ==&x-amz-credential=AKIA6L6R7QE56F6GMG5E/20201116/us-east-1/s3/aws4_request", "headers": { "Content-MD5": "1jnGuPv7xwPiat6NesKL/w==" } } }
  1. Enregistrez les valeurs suivantes :

Étape 8 : Charger la pièce jointe

Upload to an Amazon S3 bucket the attachment that the seller uploaded to your application in Step 5. Get an attachment from the seller (if supported).

L'exemple de code Java de cette étape applique une logique permettant de charger une pièce jointe et utilise le client HTTP Apache.

Utilisez ce qui suit comme entrée pour l'exemple de code :

Exemple de code Java

package io.swagger.client.util; import java.io.IOException; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.Map; import io.swagger.client.model.CreateUploadDestinationResponse; public class UploadFileToDestination { private static String requestMethod = "PUT"; private static String contentType = "Content-Type"; private static String contentValue = "application/text"; private static URL url; private static Map < String, String > headers; /* Upload file to destination using the response returned in CreateUploadDestination. Reference https://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObjectJavaSDK.html) */ public static void uploadFileInDestination( CreateUploadDestinationResponse uploadDestinationPayload) throws IOException { url = new URL(uploadDestinationPayload.getPayload().getUrl()); headers = (Map < String, String > )uploadDestinationPayload.getPayload() .getHeaders(); // Create the connection and use it to upload the new object using the // pre-signed URL. HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod(requestMethod); connection.setRequestProperty(contentType, contentValue); // headers that are returned in createDestination call for (Map.Entry < String, String > headersEntry: headers.entrySet()) { connection.setRequestProperty(headersEntry.getKey(), headersEntry.getValue()); } OutputStreamWriter out = new OutputStreamWriter( connection.getOutputStream()); out.write("Text of the file"); out.close(); // Check the HTTP response code. To complete the upload and make the // object available, // you must interact with the connection object in some way. connection.getResponseCode(); System.out.println("HTTP response code: " + connection.getResponseCode() + connection.getResponseMessage()); connection.disconnect(); } }

La pièce jointe est chargée dans le compartiment Amazon S3.

Étape 9 : Envoyer un message à l'acheteur

To send a message from the seller to the buyer you need to call the operation that corresponds to the message type that the seller chose in Step 2. Get a list of available message types. For example, if the seller chose the "Confirm customization details" message type, you would call the confirmCustomizationDetails operation. Refer to the Messaging API reference for the list of operations that are available. In this example, we will call the confirmCustomizationDetails operation.

  1. Appelez l'opération confirmCustomizationDetails de l'API Messagerie, en fournissant les paramètres suivants :

Paramètre de chemin d'accès :

Paramètre Description Obligatoire
amazonOrderId An Amazon order identifier. This specifies the order for which a message is to be sent. Use the Amazon order identifier that you saved in Step 1. Get the order for which the seller wants to send a message.

Type : chaîne

Oui

Paramètre de requête :

Paramètre Description Obligatoire
marketplaceIds Ce paramètre correspond à un identifiant de site de vente. Il indique le site de vente sur lequel la commande a été passée. Notez que vous ne pouvez spécifier qu'un seul site de vente.

Type : array[string]

Oui

Paramètres du corps :

Paramètre Description Obligatoire
text The custom message to be included in the email to the buyer. Use the message text from Step 4. Get custom message text from the seller (if supported).

Type : chaîne

Oui
attachments Pièces jointes à inclure dans le message destiné à l'acheteur Oui

Exemple de demande

POST https://sellingpartnerapi-na.amazon.com/messaging/v1/orders/902-6786204-8179805/messages/confirmCustomizationDetails?marketplaceIds=ATVPDKIKX0DER { "text": "This is the message from the seller to the buyer that will appear in the email to the buyer.", "attachments": [ { "uploadDestinationId": "4370d51b-2954-445c-9f30-EXAMPLE6b9de", "fileName": "example.txt" } ] }

Réponse

Il n'y a pas de réponse. À la place, Amazon envoie le message du vendeur à l'acheteur par e-mail.


Cette page vous a-t-elle été utile ?