Placing an order with the GraphQL API
An order is how a customer's finished designs are submitted for fulfillment. If you aren't using an official e-commerce plugin, you place the order yourself, for example when your store reports that a cart has been paid for. This tutorial shows how to do that from your server with the GraphQL API. There are two mutations to choose from, depending on whether you already have a bundle.
Using the orderCreate mutation
This is the flow to follow if you already have a Spiff bundle, for example one created with the Core SDK.
You can create and update bundles using the Core SDK or the GraphQL API. If you are using the Core SDK, you can also call bundle.placeOrder() to place the order for you.
-
Get an application key from the hub.
-
For each item to be ordered, get the amount to order and the Spiff bundle ID.
-
Construct a request body in the form expected by the orderCreate mutation. Each entry in
orderItemsis an OrderItemInput with anamountToOrderand abundleId. You can pass atransactionIdinstead to order a single design, but it is ignored if abundleIdis set.
mutation {
orderCreate(
externalId: "ext-123"
orderItems: [{ amountToOrder: 1, bundleId: "00000000-0000-0000-0000-000000000000" }]
) {
id
}
}
-
Set the URL, HTTP method and headers of your request as described in our GraphQL basics page.
-
Submit the request.
Using the orderCreateSimpleAsync mutation
This is a flow that you may follow if you do not already have a Spiff bundle.
However, this mutation does not provide full control over the creation of orders in SpiffCommerce. To have maximum control over the creation of orders in SpiffCommerce, use the orderCreate mutation as described above.
-
Get an application key from the hub.
-
For each item to be ordered, construct an OrderSimpleBundleInput or OrderSimpleItemInput.
-
Construct a request body in the form expected by the orderCreateSimpleAsync mutation.
-
Set the URL, HTTP method and headers of your request as described in our GraphQL basics page.
-
Submit the request.