Skip to main content

Punchout

The final step of using the Storefront API for Amazon Business is to add the product to the shopping cart. The simplest way of achieving that is to initiate an OCI punchout to the detail page on Amazon.

caution

Right now, you cannot add the product/offer to the shopping cart directly. You must do so by performing a punchout to Amazon. We have simplified this process to reduce your efforts to a minimum.

In the future, you might be able to directly add a product/offer to the shopping cart. However, this comes with additional complexities regarding your order process. So, for now, using OCI punchout is the simplest option you can choose.

Prerequisites

To follow this tutorial, you will need:

  1. A Storefront installation with a properly configured connection to Amazon Business as described in the Setup guide.
  2. A process of creating access tokens as described in the Authorization guide.

Initiating the punchout process

Once again, we need to use an access token (YOUR_ACCESS_TOKEN) to authenticate your request. You will also need to pass the YOUR_PRODUCT_ID again to initiate the punchout process. Finally, we will need a YOUR_HOOK_URL that we will use to return the shopping cart to your system as it is returned by Amazon.

curl --request POST \
--header 'authorization: YOUR_ACCESS_TOKEN' \
--url 'https://YOUR_DOMAIN/api/v1/amazon/products/YOUR_PRODUCT_ID/punchout'
--data '{"callbackUrl": "YOUR_HOOK_URL"}'

Parameters

ParameterInTypeRequiredDescription
idpathstringtrueID of the product to punchout

Request Body

The request body is a JSON object.

ParameterTypeRequiredDescription
callbackUrlstringtrueHOOK_URL of the OCI punchout process. This URL will always be used, even in failure; in other words, we try everything to pass control back to the caller.
namestringfalseFull name of the requester, e.g. "Joe Average". It is being used e.g. in shipping notifications
shipToobject(Address)falseShipment address (see below). If it is not specified here, Amazon may fallback to using the default address of the group/organization, which more often than not is a bad idea.

Example:

{
"callbackUrl": "https://example.com/oci/callback",
"name": "Joe Average",
"shipTo": {
"street": "525 Market St",
"city": "San Francisco",
"postalCode": "94105",
"state": "CA",
"countryCode": "US",
"country": "United States of America"
}
}

Shipment address

The parameters of the shipment address are the same as those in the cXML specification.

ParameterDescription
addressId(optional) ID of the address.
addressIdDomain(optional) Domain of the address ID.
street(optional) Street.
cityCode(optional) City code.
city(optional) City name.
stateCode(optional) State code.
state(optional) State.
postalCode(optional) Postal code.
countryCode(optional) Country code, e.g. US.
country(optional) Country name.

Response

If everything goes well, you will receive a successful HTTP response with status 201 Created with a payload containing a URL that you can send to the user agent to follow.

{
"redirectUrl": "https://www.amazon.com/eprocurement/initiate-clean-punchout/123-4567890-1234567"
}

Asking the user agent to redirect to this URL will bring the end-user to the detail page of the product on Amazon Business. When the user adds the product to the shopping cart and completes the punchout procedure, the product gets returned to the HOOK_URL specified in callbackUrl as with any other shop connected via OCI punchout.

Errors

In case of an error, you can use the HTTP status code and the response body to find out what went wrong.

Example:

{
"error": {
"code": 400,
"message": "Please check the request parameters.",
"details": [
"You must specify a callbackUrl in the body of the request."
]
}
}