Cancel a Buy with Prime Order

📘

Important

The Buy with Prime API is offered as a preview and might change as we receive feedback and iterate on the interfaces. We are sharing this early documentation to help you learn about the Buy with Prime API as we write and iterate on the content.

This topic provides examples of how to use the Order interface to cancel a Buy with Prime order.

To learn how to call the Buy with Prime API, see Call the Buy with Prime API.

Request order cancellation

This example shows how to request order cancellation.

Request
// GraphQL mutation
mutation cancelOrder{
    cancelOrder(
        orderIdentifier: { 
          orderId: "example-order-id" 
        }
        input: {
            aliases: [{
                aliasType: "EXT_CANCEL_ID"
                aliasId: "example-external-cancellation-id"
              }
            ]
            reason: "ORDERED_BY_MISTAKE"
            additionalComments: "Order placed by mistake"
    }
    ) {
    cancellation {
       id
       aliases {
         aliasType
         aliasId
       }
       state
       reason
       additionalComments
       createdAt
       updatedAt
       canceledFor {
         orderLineItems {
           lineItem {
             id
           }
           amount {
             value
             unit
           }
         }
       }
     }
   }
 }
Response
{
    "data": {
        "cancelOrder": {
            "cancellation": {
                "id": "example-cancellation-id",
                "state": "PENDING",
                "aliases": [
                   {
                      "aliasId": "example-external-cancellation-id",
                      "aliasType": "EXT_CANCEL_ID"
                   }
                ],
                "reason": "ORDERED_BY_MISTAKE",
                "additionalComments": "Order placed by mistake",
                "createdAt": "2024-07-19T06:47:22.138Z",
                "updatedAt": "2024-07-19T06:47:22.138Z",
                "requestedBy": "MERCHANT",
                "canceledFor": {
                    "orderLineItems": [
                      {
                           "lineItem": {
                              "id": "example-line-item-id"
                           },
                           "amount": {
                              "value": 1,
                              "unit": "ONE"
                           }
                       }
                    ]
                }
            }
        }
    }
}

Request order cancellation with only an order identifier

This example shows how to request cancellation with only an order identifier.

Request
// GraphQL mutation
mutation cancelOrder{
    cancelOrder(
        orderIdentifier: { 
          orderId: "example-order-id" 
        }
    ) {
    cancellation {
       id
       aliases {
         aliasType
         aliasId
       }
       state
       reason
       additionalComments
       createdAt
       updatedAt
       canceledFor {
         orderLineItems {
           lineItem {
             id
           }
           amount {
             value
             unit
           }
         }
       }
     }
   }
 }
Response
{
    "data": {
        "cancelOrder": {
            "cancellation": {
                "id": "example-cancellation-id",
                "state": "PENDING",
                "aliases": [],
                "reason": null,
                "additionalComments": null,
                "createdAt": "2024-07-05T18:15:53.662Z",
                "updatedAt": "2024-07-05T18:15:53.662Z",
                "requestedBy": "MERCHANT",
                "canceledFor": {
                    "orderLineItems": [
                       {
                          "lineItem": {
                             "id": "example-line-item-id"
                          },
                          "amount": {
                              "value": 1,
                              "unit": "ONE"
                           }
                       }
                    ]
                }
            }
        }
    }
}

Request order cancellation when your reason isn't in the reason list

This example shows how to request order cancellation and provide a cancellation reason that's not in the cancellation reason list. In this case, choose OTHER as the reason and add your reason in the note field.

Request
// GraphQL mutation
mutation cancelOrder{
    cancelOrder(
        orderIdentifier: { 
          orderId: "example-order-id" 
        }
        input: {
            aliases: [{
               aliasType: "EXT_CANCEL_ID"
               aliasId: "example-external-cancellation-id"
              }
            ]
            reason: "OTHER"
            note: "DAMAGED PRODUCT"
    }
    ) {
    cancellation {
       id
       aliases {
         aliasType
         aliasId
       }
       state
       reason
       additionalComments
       createdAt
       updatedAt
       canceledFor {
         orderLineItems {
           lineItem {
             id
           }
           amount {
             value
             unit
           }
         }
       }
     }
   }
 }
Response
{
    "data": {
        "cancelOrder": {
            "cancellation": {
                "id": "example-cancellation-id",
                "state": "PENDING",
                "aliases": [
                  {
                     "aliasId": "cancel-ext-1",
                     "aliasType": "external-cancellation-id"
                  }
                ],
                "reason": "OTHER",
                "additionalComments": "DAMAGED PRODUCT",
                "createdAt": "2024-07-19T06:47:22.138Z",
                "updatedAt": "2024-07-19T06:47:22.138Z",
                "requestedBy": "MERCHANT",
                "canceledFor": {
                    "orderLineItems": [
                        {
                            "lineItem": {
                                "id": "example-line-item-id"
                            },
                            "amount": {
                                "value": 1,
                                "unit": "ONE"
                            }
                        }
                    ]
                }
            }
        }
    }
}

Related topics