Create a Delivery Preview for Checkout

📘

Buy with Prime API is now available for early access

Sign up for early access to the Buy with Prime API using the 'Sign Up' button below. The API may change as Amazon receives feedback and iterates on it.

This topic contains examples of requests and responses that show how to Create Delivery Previews that you can display on a checkout page.

Delivery Preview on a Checkout Page

Delivery Preview on a Checkout Page

To generate a precise delivery preview that you can use to create an order, use accurate delivery terms. In the deliveryPreview query, include the shopper identity, and in DeliveryLocationInput include all attributes related to the shipping address.

Sample data

The examples in this topic use the following sample data.

Sample catalog data
val inSearchOfLostTime = {
    title: "In Search of Lost Time",
    isbn: "example-isbn-1",
    isPrimeIntended: true,
    sku: "example-sku-1",
    mSku: "example-msku-1",
    imageUrl: "https://example.com/images/example-image-1.jpg",
    detailPageUrl: "https://www.amazon.com/dp/example-detail-page-1"
};
val prideAndPrejudice = {
    title: "Pride and Prejudice",
    isbn: "example-isbn-2",
    isPrimeIntended: true,
    sku: "example-sku-2",
    mSku: "example-msku-2",
    imageUrl: "https://example.com/images/example-image-2.jpg",
    detailPageUrl: "https://www.amazon.com/dp/example-detail-page-2"
};
val warAndPeace = {
    title: "War and Peace",
    isbn: "example-isbn-3",
    isPrimeIntended: false,
    sku: "example-sku-3",
    mSku: "example-msku-3",
    imageUrl: "https://example.com/images/example-image-3.jpg",
    detailPageUrl: "https://www.amazon.com/dp/example-detail-page-3"
};

Get a delivery preview for a single product

The following example uses the deliveryPreview query to get the delivery preview for a single product. To improve the accuracy and reliability of the delivery options presented to the shopper during checkout, this example takes into account all attributes related to the shipping address that the shopper entered, and the shopper identity.

Request
# Variables from sample data
inSearchOfLostTime

// GraphQL query
query deliveryPreview($input: DeliveryPreviewInput!) {
    deliveryPreview(input: $input) {
      id
      deliveryGroups {
        id
        deliveryOffers {
          id
          date {
            earliest
            latest
          }
          policy {
            messaging {
              messageText
              locale
              badge
            }
          }
          expiresAt
        }
      }
    }
  }

// Query variables
{
  "input": {
    "products": [
      {
        "productIdentifier": {
          "SKU": inSearchOfLostTime.sku
        },
        "amount": {
          "unit:" "UNIT",
          "value": 1
        }
      }
    ],
    "location": {
      "shippingAddress": {
        "name": "Jane Doe",
        "streetAddress": "410 Terry Ave N",
        "locality": "Seattle",
        "region": "WA",
        "postalCode": "98109",
        "countryCode": "US"
      }
    },
    "shopperIdentity": {
      "lwaAccessToken":{
        "value": "EXAMPLE_LWA_ACCESS_TOKEN",
        "externalId": "EXAMPLE_EXTERNAL_ID"
      }
    }
  }
}

Response
{
  "data":{
    "deliveryPreview":{
      "id":"example-delivery-preview-id",
      "deliveryGroups":[
        {
          "id":"example-delivery-group-id",
          "deliveryOffers":[
            {
              "id":"example-delivery-offer-id",
              "date":{
                "earliest":"2023-12-06T04:00:00Z",
                "latest":"2023-12-06T04:00:00Z"
              },
              "deliveryTerms":{
                "isPrimeEligible": true
              },              
              "policy":{
                "messaging":{
                  "messageText":"Get it as soon as tomorrow, Dec 6",
                  "locale":"en-US",
                  "badge":"PRIME"
                }
              },
              "expiresAt":null
            }
          ]
        }
      ]
    }
  }
}

Get a delivery preview for multiple products

The following example uses the deliveryPreview query to get the delivery preview for a multiple products. To improve the accuracy and reliability of the delivery options presented to the shopper during checkout, this example takes into account all attributes related to the shipping address that the shopper entered, and the shopper identity.

Request
# Variables from sample data
inSearchOfLostTime
prideAndPrejudice

// GraphQL query
query deliveryPreview($input: DeliveryPreviewInput!) {
    deliveryPreview(input: $input) {
      id
      deliveryGroups {
        id
        products {
          productIdentifier {
            value
          }
          amount {
            unit
            value
          }
        }
        deliveryOffers {
          id
          date {
            earliest
            latest
          }
          policy {
            messaging {
              messageText
              locale
              badge
            }
          }
          expiresAt
        }
      }
    }
  }

// Query variables
{
  "input": {
    "products": [
      {
        "productIdentifier": {
          "SKU": inSearchOfLostTime.sku
        },
        "amount": {
          "unit:" "UNIT",
          "value": 1
        }
      },
      {
        "productIdentifier": {
          "SKU": prideAndPrejudice.sku
        },
        "amount": {
          "unit:" "UNIT",
          "value": 1
        }
      }
    ],
    "location": {
      "shippingAddress": {
        "name": "Jane Doe",
        "streetAddress": "410 Terry Ave N",
        "locality": "Seattle",
        "region": "WA",
        "postalCode": "98109",
        "countryCode": "US"
      }
    },
    "shopperIdentity": {
      "lwaAccessToken":{
        "value": "EXAMPLE_LWA_ACCESS_TOKEN",
        "externalId": "EXAMPLE_EXTERNAL_ID"
      }
    }
  }
}

Response
{
  "data":{
    "deliveryPreview":{
      "id":"example-delivery-preview-id",
      "deliveryGroups":[
        {
          "id":"example-delivery-group-id",
          "products":[
            {
              "productIdentifier":{
                "value":"example-sku-1"
              },
               "amount": {
                 "unit:" "UNIT",
                 "value": 1
              }
            }
          ],
          "deliveryOffers":[
            {
              "id":"example-delivery-offer-id-1",
              "date":{
                "earliest":"2023-12-07T04:00:00Z",
                "latest":"2023-12-07T04:00:00Z"
              },
              "deliveryTerms":{
                "isPrimeEligible": true
              },              
              "policy":{
                "messaging":{
                  "messageText":"Get it as soon as Thursday, Dec 7",
                  "locale":"en-US",
                  "badge":"PRIME"
                }
              },
              "expiresAt":null
            }
          ]
        },
        {
          "id":"example-delivery-offer-id-2",
          "products":[
            {
              "productIdentifier":{
                "value":"example-sku-2"
              },
              "amount": {
                 "unit:" "UNIT",
                 "value": 1
              }
            }
          ],
          "deliveryOffers":[
            {
              "id":"dbf63bfc-aa0a-4f6a-8d51-da419b310932",
              "date":{
                "earliest":"2023-12-0704:00:00Z",
                "latest":"2023-12-07T04:00:00Z"
              },
              "deliveryTerms":{
                "isPrimeEligible": true
              },              
              "policy":{
                "messaging":{
                  "messageText":"Get it as soon as Thursday, Dec 7",
                  "locale":"en-US",
                  "badge":"PRIME"
                }
              },
              "expiresAt":null
            }
          ]
        }
      ]
    }
  }
}

Related topics