Magento 2 How to create order using GraphQL
In this article, we will show you how to create order using GraphQL. The placeOrder
mutation converts the cart into an order and returns an Order ID. We 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.
The following actions are perform before using 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 (use
setGuestEmailOnCart
)
Syntax
mutation {
placeOrder(
input: PlaceOrderInput
) {
PlaceOrderOutput
}
}
The following example for create order.
Request
saveCopyzoom_out_mapmutation {
placeOrder(
input: {
cart_id: "tfwJXU8gMmjjXqcKyINO3ydMSsRd5Ogy"
}
) {
order {
order_number
}
}
}
Response
saveCopyzoom_out_map{
"data": {
"placeOrder": {
"order": {
"order_number": "000000004"
}
}
}
}
That's it!!
If you are looking for more GraphQL solutions then check out our another article which is List of GraphQL Queries and Mutations for Magento 2.
I hope this article helps you to find what you were looking for.
Bookmark it for your future reference. Do comment below if you have any other questions on that.
P.S. Do share this article with your team.