placeOrder mutation
The placeOrder mutation converts the cart into an order and returns an order ID. You cannot manage orders with GraphQL, because orders are part of the backend. You can use REST or SOAP calls to manage orders to their completion.
Perform the following actions before using the placeOrder mutation:
- Create an empty cart
- Add one or more products to the cart
- Set the billing address
- Set the shipping address
- Set the shipping method
- Set the payment method
- For guest customers, assign an email to the cart
As of Commerce 2.4.9, the PlaceOrderOutput object contains the errors available on the top of the response node. This assures easy error control and provides compatibility with older versions.
As of Commerce 2.4.7, the PlaceOrderOutput object can contain orderV2, which provides full details about the order. When the mutation runs, Commerce generates and returns a token in the orderV2.token field. You can supply the token value to the guestOrderByToken query to retrieve details about an order created by a guest shopper.
data-variant=info
data-slots=text
placeOrder mutation runs asynchronously if the AsyncOrder module has been enabled. By default, the mutation runs synchronously. Asynchronous order placement describes the benefits of enabling the module.Syntax
mutation {
placeOrder(
input: PlaceOrderInput
) {
PlaceOrderOutput
}
}
Reference
The placeOrder reference provides detailed information about the types and fields defined in this mutation.
Example usage
Request:
mutation {
placeOrder(
input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG"
}
) {
orderV2 {
number
token
}
}
}
Response:
{
"data": {
"placeOrder": {
"orderV2": {
"number": "000000006",
"token": "0:3:OSScWU6PKLn3kFyMhNWyskG0opgVvFBnJmtuaFHKGwDFT83S6Kv9U39iYwixuU+vhwDz2AF4pCs3GtLhHbQ="
}
}
}
}
Errors
CART_NOT_FOUNDCould not find a cart with IDCART_NOT_ACTIVEThe cart isn't active.GUEST_EMAIL_MISSINGGuest email for cart is missing.UNABLE_TO_PLACE_ORDERA server error stopped your order from being placed. Please try to place your order againUNABLE_TO_PLACE_ORDERSome addresses can't be used due to the configurations for specific countriesUNABLE_TO_PLACE_ORDERThe shipping method is missing. Select the shipping method and try againUNABLE_TO_PLACE_ORDERPlease check the billing address informationUNABLE_TO_PLACE_ORDEREnter a valid payment method and try againUNABLE_TO_PLACE_ORDERSome of the products are out of stockUNDEFINEDUNDEFINED