Change the State of a Return in the Sandbox
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.
In the sandbox environment, you call the mutation updateOrderReturns
to move a return package through various states to publish events without making real-world changes. For example, you can test how your application handles a RETURN_PACKAGE_DELIVERED
event without actually delivering and then returning a package by setting the return package state to DELIVERED
.
The response to updateOrderReturns
contains the current order. You must wait for the state change to happen, and then you can query the order
for the updated details. T
Reference: updateOrderReturns
updateOrderReturns
In the sandbox environment, you can make the following state transitions to returns by calling updateOrderReturns
with ReturnDetailsStateInputv20240101
.
Input argument | Current state | Next state | Expected events | Expected wait |
---|---|---|---|---|
ReturnDeliveryDetails | CREATED | COMPLETED | RETURN_DELIVERY_COMPLETED , REFUND_REQUESTED | 2 minutes |
ReturnDeliveryDetails | COMPLETED | None, this is a terminal state |
Query the order
Use the following query to get relevant ReturnDetails
from the order
.
Request
query order($orderIdentifier: OrderIdentifierInput!) {
order(orderIdentifier: $orderIdentifier) {
id
returns {
details {
id
state
returnFor {
orderLineItems {
lineItem {
id
}
returnedQuantity {
amount
unit
}
}
}
}
}
}
}
//Query variables
{
"orderIdentifier": {
"orderId": "example-order-id"
}
}
Prerequisites
- Create a Buy with Prime Order.
- Trigger fulfillment by doing one of the following:
- In the
createOrder
call, set thedesiredExecutionState
asSTARTED
. - Trigger fulfillment for an existing order.
- In the
- Update all of the packages in the order to
DELIVERED
. For details, see Update multiple packages as DELIVERED. - Using the Merchant Online Return Center, create a return for all or some of the items. For details, see Create returns on behalf of customer.
Examples
Update a return package as COMPLETED
COMPLETED
Events published: RETURN_COMPLETED
The following example shows how to mark a return completed.
Request
mutation updateOrderReturns($input: UpdateOrderReturnsInput!) {
updateOrderReturns(input: $input) {
order {
id
}
}
}
//Mutation Variables
{
"input": {
"details": [
{
"id": "example-return-details-id",
"state": "COMPLETED"
}
],
"orderId": "example-order-id"
}
}
Response
{
"data": {
"updateOrderReturns": {
"order": {
"id": "example-order-id"
}
}
}
}
After you see the expected event, Query the order to view the updated details.
Query order response
{
"data": {
"order": {
"id": "example-order-id",
"returns": {
"details": [
{
"id": "example-return-details-id",
"state": "COMPLETED",
"returnFor": {
"orderLineItems": [
{
"lineItem": {
"id": "example-line-item-id"
},
"returnedQuantity": {
"amount": 1,
"unit": "ONE"
}
}
]
}
}
]
}
}
}
}
Updated 7 days ago