cancelOrder

Version 2024-11-01

📘

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.

Response

Return type CancelOrderResponse

Arguments

ArgumentDescription
input (CancelOrderInput)

Specifies the input fields to cancel an Order.

orderIdentifier (OrderIdentifierInput required)

Identifier for the order to be cancelled through this request. This could be Buy with Prime Order Id or any associated aliases.

Examples


Cancel Order Mutation With Order Id And Reason

Request

mutation cancelOrder {
    cancelOrder(
        orderIdentifier:
        {
            orderId: "322-KG36-AAAAA"
        }
        input:
        {
            aliases:
            {
                aliasId: "1234",
                aliasType: "EXTERNAL_CANCELLATION_ID"
            }
            reason: ORDERED_BY_MISTAKE
            additionalComments: "Wrong item"
        }
    ) {
        cancellation {
            id
            state
            aliases {
                aliasId
                aliasType
            }
            reason
            additionalComments
            createdAt
            updatedAt
            requestedBy
            canceledFor {
                orderLineItems {
                    lineItem {
                        id
                    }
                    amount {
                        value
                        unit
                    }
                }
            }
        }
    }
}

Response

{
  "data": {
    "cancelOrder": {
      "cancellation": {
        "id": "dd24641f9af756cfb69f12e4de8dce1a10a58ca438ca33e7fb6e19c661234567",
        "state": "PENDING",
        "aliases": [
          {
            "aliasId": "1234",
            "aliasType": "EXTERNAL_CANCELLATION_ID"
          }
        ],
        "reason": "ORDERED_BY_MISTAKE",
        "additionalComments": "Wrong item",
        "createdAt": "2024-08-22T12:58:11.722Z",
        "updatedAt": "2024-08-22T12:58:11.722Z",
        "requestedBy": "MERCHANT",
        "canceledFor": {
          "orderLineItems": [
            {
              "lineItem": {
                "id": "11312196b6-1883e00df5"
              },
              "amount": {
                "value": 4,
                "unit": "ONE"
              }
            }
          ]
        }
      }
    }
  }
}

Cancel Order Mutation With Order Alias

Request

mutation cancelOrder {
    cancelOrder(
        orderIdentifier:
        {
            alias:
            {
                aliasId: "1234",
                aliasType: "OMS_ORDER_ID"
            }
        }
        input:
        {
            aliases:
            {
                aliasId: "1234",
                aliasType: "EXTERNAL_CANCELLATION_ID"
            }
            reason: ORDERED_BY_MISTAKE
            additionalComments: "Wrong item"
        }
    ) {
        cancellation {
            id
            state
            aliases {
                aliasId
                aliasType
            }
            reason
            additionalComments
            createdAt
            updatedAt
            requestedBy
            canceledFor {
                orderLineItems {
                    lineItem {
                        id
                    }
                    amount {
                        value
                        unit
                    }
                }
            }
        }
    }
}

Response

{
  "data": {
    "cancelOrder": {
      "cancellation": {
        "id": "dd24641f9af756cfb69f12e4de8dce1a10a58ca438ca33e7fb6e19c661234567",
        "state": "PENDING",
        "aliases": [
          {
            "aliasId": "1234",
            "aliasType": "EXTERNAL_CANCELLATION_ID"
          }
        ],
        "reason": "ORDERED_BY_MISTAKE",
        "additionalComments": "Wrong item",
        "createdAt": "2024-08-22T12:58:11.722Z",
        "updatedAt": "2024-08-22T12:58:11.722Z",
        "requestedBy": "MERCHANT",
        "canceledFor": {
          "orderLineItems": [
            {
              "lineItem": {
                "id": "11312196b6-1883e00df5"
              },
              "amount": {
                "value": 4,
                "unit": "ONE"
              }
            }
          ]
        }
      }
    }
  }
}

Cancel Order Mutation With Only Order Id

Request

mutation cancelOrder {
    cancelOrder(
        orderIdentifier:
        {
            orderId: "322-KG36-AAAAA"
        }
    ) {
        cancellation {
            id
            state
            aliases {
                aliasId
                aliasType
            }
            reason
            additionalComments
            createdAt
            updatedAt
            requestedBy
            canceledFor {
                orderLineItems {
                    lineItem {
                        id
                    }
                    amount {
                        value
                        unit
                    }
                }
            }
        }
    }
}

Response

{
  "data": {
    "cancelOrder": {
      "cancellation": {
        "id": "dd24641f9af756cfb69f12e4de8dce1a10a58ca438ca33e7fb6e19c661234567",
        "state": "PENDING",
        "aliases": [],
        "reason": "",
        "additionalComments": "",
        "createdAt": "2024-08-22T12:58:11.722Z",
        "updatedAt": "2024-08-22T12:58:11.722Z",
        "requestedBy": "MERCHANT",
        "canceledFor": {
          "orderLineItems": [
            {
              "lineItem": {
                "id": "11312196b6-1883e00df5"
              },
              "amount": {
                "value": 4,
                "unit": "ONE"
              }
            }
          ]
        }
      }
    }
  }
}

Cancel Order Mutation Exception For Cancellation Ineligible Order

Request

mutation cancelOrder {
    cancelOrder(
        orderIdentifier:
        {
            orderId: "322-KG36-AAAAA"
        }
        input:
        {
            aliases:
            {
                aliasId: "Abcd1",
                aliasType: "EXTERNAL_CANCELLATION_ID"
            }
            reason: ORDERED_BY_MISTAKE
            additionalComments: "Wrong item"
        }
    ) {
        cancellation {
            id
            state
            aliases {
                aliasId
                aliasType
            }
            reason
            additionalComments
            createdAt
            updatedAt
            requestedBy
            canceledFor {
                orderLineItems {
                    lineItem {
                        id
                    }
                    amount {
                        value
                        unit
                    }
                }
            }
        }
    }
}

Response

{
  "errors": [
    {
      "message": "The order cannot be cancelled as fulfillment is in progress.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "cancelOrder"
      ],
      "extensions": {
        "classification": {
          "type": "ValidationError",
          "code": "CancellationIneligible",
          "details": {
            "message": "The order cannot be cancelled as fulfillment is in progress."
          },
          "errorType": "ValidationException",
          "errorCode": 400
        }
      }
    }
  ],
  "data": {
    "cancelOrder": null
  }
}