Create a Buy with Prime Order

📘

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 provides examples of how to create a Buy with Prime order.

The response to the createOrder mutation contains the complete order and links that you can use to direct customers where to manage their Buy with Prime order.

Note: We strongly recommend that you specify any monetary charges on the order, such as discounts or taxes, at the line-item level.

If you expect Amazon to fulfill the products associated with a delivery offer, you must provide a DeliveryOfferDetailsInput that explicitly sets the DeliveryOfferProviderInput to BUY_WITH_PRIME. You must also pass the corresponding identifiers from a DeliveryOffer generated for the products.

If you don’t expect Amazon to fulfill the delivery offer, you must set the DeliveryOfferProviderInput to MERCHANT. You can still provide as much detail as you like either by using the DeliveryOfferSummaryInput or DeliveryOfferDetailsInput.

To help the shopper understand the state of an order, we recommend that you provide as many details about orders as possible.

CreateOrderInput contains a field, desiredExecutionState, which you can set to STARTED to indicate that you want the order to be fulfilled immediately. If you want to create the order but not start fulfillment until you call the updateOrder mutation, set desiredExecutionState to NOT_STARTED. The default value of desiredExecutionState is NOT_STARTED. The following figure shows how desiredExecutionState affects order fulfillment.

How desiredExecutionState affects order fulfillment

Currently, you can create orders with a maximum of 20 items that are eligible for Buy with Prime.

To learn how to call the Buy with Prime API, see Call the Buy with Prime API. To learn how to generate Shopper Identity Tokens, see Manage Shopper Identity.

Sample data

The examples in this topic use the following sample data.

Sample product details
{
    title: "In Search of Lost Time",
    isbn: "example-isbn-1",
    isPrimeIntended: true,
    sku: "example-sku-1",
    mSku: "example-msku-1",
    buyWithPrimeProductId: "example-product-id-1",
    imageUrl: "https://example.com/images/example-image-1.jpg",
    detailPageUrl: "https://www.amazon.com/dp/example-detail-page-1",
    price: {
      amount: "10.00",
      currencyCode: "USD"
    }
    variationDetails: [
      {
      	type: "format",
        value: "Hardcover"
      },
      {
        type: "version",
        value: "Abridged"
      }
    ]
}
{
   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",
   variationDetails: [
      {
         format: "Paperback"
      }
   ]
}
Sample customer details
{
  contact: {
    name: "Jane Doe",
    email: "[email protected]"
  }
}
Sample recipient details

Typically, an individual creates an order for themselves. Less common scenarios, such as gifting, require the representation of recipients independently from the customer placing the order. To provide this flexibility, Buy with Prime doesn't assume that the customer who creates the order is the same as the person who receives it.

{
    deliveryAddress: {
       name: "John Doe",
       streetAddress: "440 Terry Ave N" ,
       locality: "Seattle",
       region: "WA",
       countryCode: "US",
       postalCode: "98109",
       contactNumber: "206-555-0100"
    }
}
Sample delivery offer details

Prior to placing the order, you provide one or more delivery offers to the customer. The customer selects a delivery offer, and you include the associated delivery preview ID and delivery offer ID from the selectedDeliveryOffer object to the createOrder mutation.

When you generate a delivery preview that you can use to create an order, it is crucial to use accurate delivery preview terms. For details, see Create Delivery Previews

# See other tab for sampleDeliveryPreviewQueryResponse

# Assume that the first delivery offer from the delivery group is selected to create a fulfillment order
deliveryPreviewId: sampleDeliveryPreviewQueryResponse["data"]["deliveryPreview"]["id"]
deliveryOfferId: sampleDeliveryPreviewQueryResponse["data"]["deliveryGroups"][0]["deliveryOffers"][0]["id"]
{
  "data": {
    "deliveryPreview": {
      "id": "example-delivery-preview-id",
      "deliveryGroups": [
        {
          "id": "example-delivery-group",
          "products": {
            "productIdentifier": {
              "value": String
            },
            "amount": {
              "unit": String,
              "value": Bigdecimal
            }          
          },              
          "deliveryOffers": [
            {
              "id": "example-delivery-offer-id-1",
              "price": {
                "totalPrice": {
                  "currencyCode": "USD",
                  "amount": 0
                },
                "rollupPrices": [
                ]
              },
              "date": {
                "earliest": "2023-08-24T03:00:00Z",
                "latest": "2023-08-28T03:00:00Z"
              },
              "policy": {
                "messaging": {
                  "messageText": "Get it on August 24",
                  "locale": "en-US",
                  "badge": "PRIME"
                }
              },
              "expiresAt": "2023-08-21T21:27:35.016842Z"
            },
            {
              "id": "example-delivery-offer-id-2",
              "price": {
                "totalPrice": {
                  "currencyCode": "USD",
                  "amount": 0
                },
                "rollupPrices": [
                ]
              },
              "date": {
                "earliest": "2023-08-26T14:14:06Z",
                "latest": "2023-08-30T14:14:06Z"
              },
              "policy": {
                "messaging": {
                  "messageText": "Get it on August 26th",
                  "locale": "en-US",
                  "badge": "PRIME"
                }
              },
              "expiresAt": null
            }
          ]
        }
      ]
    }
  }
}

Create a minimum fulfillable Buy with Prime order

This example shows how to use the createOrder mutation to create a simple Buy with Prime order. In this example, Jane Doe (the Customer) orders a book (the Product) to be delivered to John Doe (the Recipient).

Note that desiredExecutionState is set to STARTED, which means that fulfillment will start immediately. If you want to create the order but not start fulfillment right away, set desiredExecutionState to NOT_STARTED. If you set desiredExecutionState to NOT_STARTED, fulfillment of the order will not start until you call updateOrder, which sets the state to STARTED.

Request
// Variables from sample data
inSearchOfLostTimeBook
productId
inSearchOfLostTimeBookVariationDimension
inSearchOfLostTimeBookVariationDimensionValue
deliveryPreviewId
deliveryOfferId
reversalOfferId
janeDoeCustomer
johnDoeRecipient

mutation createOrder($input: CreateOrderInput!) {
  createOrder(input: $input) {
    order {
      id
    }
  }
}
  
// Mutation variables  
{
  "input": {
    "desiredExecutionState": "STARTED",
    "customer": janeDoeCustomer,
    "recipient": johnDoeRecipient,
    "lineItems": [
      {
        "product": {
          "identifier": {
            "productId": inSearchOfLostTimeBook.buyWithPrimeProductId
          },
          "title": inSearchOfLostTimeBook.title,
          "price": {
            "amount": inSearchOfLostTimeBook.price.amount,
            "currencyCode": inSearchOfLostTimeBook.price.currencyCode
          }
        },
        "amount": {
          "unit": "UNIT",
          "value": 1
        },
        "selectedDeliveryOffer": {
          "details": {
            "deliveryPreviewId": deliveryPreviewId,
            "id": deliveryOfferId,
            "deliveryProvider": "BUY_WITH_PRIME"
          }
        }
      }
    ],
    "totalPrice": {
      "value": {
        "amount": 10,
        "currencyCode": "USD"
      }
    },
    "shopperIdentity": {
      "apayCheckoutSessionId": {
        "value": "testToken",
        "externalId": "externalId1"
      }
    }
  }
}

Response
{
  "data": {
    "order": {
      "id": "example-order-id"
    }
  }
}

Create a single-item order with external order details

When you create a Buy with Prime order, Buy with Prime associates the order with a unique ID. You can also associate the order with external information such as aliases (external order identifiers that you can use to query the order later), order links (URLs for managing the order in external order management systems), and a total order price that was computed outside of Buy with Prime.

The following example shows how to supply order aliases, order links, and an order total when you create an order.

Request
// GraphQL mutation
mutation createOrder($input: CreateOrderInput!) {
  createOrder(input: $input) {
    order {
      id
    }
  }
}
  
// Mutation variables
{
  "input": {
    "aliases": [
      {
        "aliasType": "EXTERNAL_ID",
        "aliasId": "example-alias-id"
      }
    ],
    "orderLinks": [
      {
        "destinationType": "EXTERNAL_ORDER_MANAGEMENT",
        "url": "https://example.com/orders/1234"
      }
    ],
    "totalPrice": {
      "value": {
        "amount": 10,
        "currencyCode": "USD"
      }
    },
    "shopperIdentity": {
      "apayCheckoutSessionId": {
        "value": "testToken",
        "externalId": "externalId1"
      }
    },
    "lineItems": [
      {
        "aliases": [
          {
            "aliasType": "EXTERNAL_ID",
            "aliasId": "example-line-item-alias-id"
          }
        ],
        "selectedDeliveryOffer": {
          "details": {
            "deliveryOfferFor": {
              "orderLineItemAmounts": {
                "lineItemId": {
                  "alias": {
                    "aliasType": "EXTERNAL_ID",
                    "aliasId": "example-line-item-alias-id"
                  }
                }
              }
            }
          }
        }
      }
    ],
    ...
  }
}
Response
{
  "data": {
    "order": {
      "id": "example-order-id"
    }
  }
}

Create an order that includes an item that isn't eligible for Buy with Prime

You can create orders that include items that aren't eligible for Buy with Prime. The following example shows how to create an order that contains an item that's eligible for Buy with Prime (In Search of Lost Time) and an item that's not eligible for Buy with Prime (Pride and Prejudice).

Request
// Variables from sample data
inSearchOfLostTimeBook # Eligible for Buy with Prime
prideAndPrejudiceBook # Not eligible for Buy with Prime
selectedDeliveryPreview
janeDoeCustomer
johnDoeRecipient

// GraphQL mutation
mutation createOrder($input: CreateOrderInput!) {
  createOrder(input: $input) {
    order {
      id
    }
  }
}
  
// Mutation variables
{
  "input": {
    "desiredExecutionState": "STARTED",
    "customer": janeDoeCustomer,
    "recipient": johnDoeRecipient,
    "lineItems": [
      {
        "product": {
          "identifier": {
            "productId": inSearchOfLostTimeBook.buyWithPrimeProductId
          },
          "title": inSearchOfLostTimeBook.title,
          "price": {
            "amount": inSearchOfLostTimeBook.price.amount,
            "currencyCode": inSearchOfLostTimeBook.price.currencyCode
          },
          "variationSelections": [ 
            {
              "dimension": inSearchOfLostTimeBook.variationDetails.[0].dimension,
              "value": inSearchOfLostTimeBook.variationDetails.[0].value
            }
          ]
        },
        "amount": {
          "unit": "UNIT",
          "value": 1
        },
        "selectedDeliveryOffer": {
          "details": {
            "id": selectedDeliveryPreview.deliveryOfferId,
            "deliveryPreviewId": selectedDeliveryPreview.deliveryPreviewId,
            "deliveryProvider": "BUY_WITH_PRIME"
          }
        }
      },
      {
        "product": {
          "identifier": {
            "productId": productId
          },
          "title": prideAndPrejudiceBook.title,
          "price": {
            "amount": prideAndPrejudiceBook.price.amount,
            "currencyCode": prideAndPrejudiceBook.price.currencyCode
          },
          "variationSelections": [ 
            {
              "dimension": prideAndPrejudiceBook.variationDetails.[0].dimension,
              "value": prideAndPrejudiceBook.variationDetails.[0].value
            }
          ]
        },
        "amount": {
          "unit": "UNIT",
          "value": 1
        },
        "selectedDeliveryOffer": {
          "details": {
            "deliveryProvider": "MERCHANT",
            "deliveryCharge": {
               "amount": "3.00",
               "currencyCode": "USD"
            }
          }
        }
      }
    ],
    "discounts": {
      "summary": {
        "amount": {
          "amount": 10,
          "currencyCode": "USD"
        },
        "displayString": "FIRSTORDER (coupon code)"
      }
    },
    "totalPrice": {
      "value": {
        "amount": 10,
        "currencyCode": "USD"
      }
    },
    "shopperIdentity": {
      "apayCheckoutSessionId": {
        "value": "testToken",
        "externalId": "externalId1"
      }
    },
    "payments": {
      "summary": {
        "amount": {
          "amount": "10.20",
          "currencyCode": "USD"
        },
        "paymentMethodDisplayString": "CREDIT_CARD",
        "state": "CAPTURED"
      }
    }
  }
}
Response
{
  "data": {
    "order": {
      "id": "example-order-id"
    }
  }
}

Create an order with items that belong to a bundled product

The following example shows how to use the createOrder mutation to support bundled product attribution for each line item in the order if the shopper purchases the component as part of a bundled product. When you create the order, in PurchasedProductView specify the optional purchaseGroupMembership field to provide the connection to the bundled product. Within purchaseGroupMembership, use the product field to provide the bundled product view, and use the optional memberAmount field to provide the quantity of the line item attributed to the bundled product.

The following example shows how to create a Buy with Prime order with items that belong to a bundled product while providing only the required fields to fulfill the order.

Request
// GraphQL mutation
mutation createOrder {
    createOrder(
        input: {
            lineItems: [
                {
                    product: {
                        identifier: {
                            productId: "example-component-product-1-id"
                        }
                        title: "example-component-product-1-title"
                        price: {
                            amount: 10.79
                            currencyCode: "USD"
                        }
                        purchaseGroupMembership: {
                            product: {
                                identifier: {
                                    sku: "BUNDLE-PRODUCT-TEST"
                                }
                            }
                        }
                    }
                    amount: {
                        value: 1
                    }
                    selectedDeliveryOffer: {
                        details: {
                            id: "1234567890"
                            deliveryPreviewId: "SIP-0000000-000000"
                            deliveryProvider: BUY_WITH_PRIME
                        }
                    }
                },
                {
                    product: {
                        identifier: {
                            productId: "example-component-product-2-id"
                        }
                        title: "example-component-product-2-title"
                        price: {
                            amount: 5
                            currencyCode: "USD"
                        }
                        purchaseGroupMembership: {
                            product: {
                                identifier: {
                                    sku: "BUNDLE-PRODUCT-TEST"
                                }
                            }
                        }
                    }
                    amount: {
                        value: 2
                    }
                    selectedDeliveryOffer: {
                        details: {
                            id: "0987654321"
                            deliveryPreviewId: "SIP-0000000-000000"
                            deliveryProvider: BUY_WITH_PRIME
                        }
                    }
                }
            ]
            customer: {
                contact: {
                    emailData: {
                        name: "John Smith"
                        email: "[email protected]"
                    }
                }
            }
            recipient: {
                deliveryAddress: {
                    name: "John Smith"
                    streetAddress: "399 Boren Ave N"
                    locality: "Seattle"
                    region: "WA"
                    countryCode: "US"
                    postalCode: "98109"
                }
            }
            totalPrice: {
                value: {
                    amount: 20.79
                    currencyCode: "USD"
                }
            }
            orderLinks: [
                {
                    destinationType: EXTERNAL_ORDER_MANAGEMENT
                    url: "https://mystore123.com/orders/512968435"
                }
            ]
            shopperIdentity: {
                apayCheckoutSessionId: {
                    value: "apay-session-id"
                    externalId: "external-shopper-checkout-session-id"
                }
            }
        }
    ) {
        order {
            id
            lineItems {
                amount {
                    unit
                    value
                }
                createdAt
                product {
                    title
                    price {
                        currencyCode
                        amount
                    }
                    purchaseGroupMembership {
                        product {
                            sku
                        }
                    }
                }
            }
            orderLinks {
                destinationType
                url
            }
        }
    }
}
Response
{
  "data": {
    "createOrder": {
      "order": {
        "id": "322-ABC1-AAAAAA",
        "lineItems": [
          {
            "amount": {
              "unit": "ONE",
              "value": 1
            },
            "createdAt": "2022-02-22T16:13:11.798Z",
            "product": {
              "title": "example-component-product-1-title",
              "price": {
                "currencyCode": "USD",
                "amount": 10.79
              },
              "purchaseGroupMembership": {
                "product": {
                  "sku": "BUNDLE-PRODUCT-TEST"
                }
              }
            }
          },
          {
            "amount": {
              "unit": "ONE",
              "value": 2
            },
            "createdAt": "2022-02-22T16:13:11.798Z",
            "product": {
              "title": "example-component-product-2-title",
              "price": {
                "currencyCode": "USD",
                "amount": 5
              },
              "purchaseGroupMembership": {
                "product": {
                  "sku": "BUNDLE-PRODUCT-TEST"
                }
              }
            }
          }
        ],
        "orderLinks": [
          {
            "destinationType": "EXTERNAL_ORDER_MANAGEMENT",
            "url": "https://mystore123.com/orders/512968435"
          }
        ]
      }
    }
  }
}

Use a delivery offer to create a Buy with Prime order

The following example shows how to pass a delivery offer to the createOrder mutation. When you create the order, you specify the selectedDeliveryOffer for each line item.

In the DeliveryOfferDetails, make sure to provide both the deliveryPreviewId and the id for accurate representation of the chosen delivery option within the finalized order.

Request
# Variables from sample data
inSearchOfLostTimeBook
deliveryPreviewId
deliveryOfferId
reversalOfferId
janeDoeCustomer
johnDoeRecipient

// GraphQL mutation
mutation createOrder($input: CreateOrderInput!) {
  createOrder(input: $input) {
    order {
      id
    }
  }
}
    
// Mutation variables  
{
  "input": {
    "desiredExecutionState": "STARTED",
    "customer": janeDoeCustomer,
    "recipient": johnDoeRecipient,
    "lineItems": [
      {
        "product": {
          "identifier": {
            "productId": productId
          },
          "title": inSearchOfLostTimeBook.title,
          "price": {
            "amount": inSearchOfLostTimeBook.price.amount,
            "currencyCode": inSearchOfLostTimeBook.price.currencyCode
          }
        },
        "amount": {
          "unit": "UNIT",
          "value": 1
        },
        "selectedDeliveryOffer": {
          "details": {
            "id": selectedDeliveryPreview.deliveryOfferId,
            "deliveryPreviewId": selectedDeliveryPreview.deliveryPreviewId,
            "deliveryProvider": "BUY_WITH_PRIME"
          }
        }
      }
    ],
    "shopperIdentity": {
      "apayCheckoutSessionId": {
        "value": "testToken",
        "externalId": "externalId1"
      }
    }
  }
}
Response
{
  "data": {
    "order": {
      "id": "example-order-id"
    }
  }
}

Related topics