Crystallize logo

Creating Orders

So far, we have only worked with fetching data via the Order API. This section explains how you can create an order using the API. It’s also possible to create and manage orders using the Crystallize App.

In order to perform these operations, ensure that you have the proper authentication (if necessary) and user permissions.

Create Order

In order to create an order via the API, we’ll be using GraphQL mutations. Refer to our GraphQL sample for creating an order, which is part of our example repository. Also check out the API docs at https://api.crystallize.com/your-tenant-identifier/orders for the full list of parameters you can specify and fetch.

The example mutation below takes information about the customer and the cart, as well as the payment details. Once an order is created, you get back the order ID.

Note that orders are created asynchronously. There is no guarantee that the order will be retrievable immediately after registering it.

mutation createOrder {
  orders {
    create(
      input: {
        customer: {
          firstName: "Crystal"
          lastName: "Ecommerce"
          identifier: "cus_0001"
          addresses: [
            {
              type: billing
              street: "Kverndalsgata"
              streetNumber: "8"
              city: "Skien"
              country: "Norway"
              postalCode: "1234"
            }
            {
              type: delivery
              street: "Kverndalsgata"
              streetNumber: "8"
              city: "Skien"
              country: "Norway"
              postalCode: "1234"
            }
          ]
        }
        cart: {
          name: "Calathea"
          sku: "maranta-leuconeura-1611849929203"
          quantity: 1
          price: {
            currency: "EUR"
            tax: { name: "No Tax", percent: 0 }
            net: 23
            gross: 23
          }
        }
        payment: [
          {
            provider: stripe
            stripe: {
              orderId: "ord_0001"
              customerId: "cus_0001"
              paymentMethod: "card"
              paymentIntentId: "pi_0001"
              metadata: null
            }
          }
        ]
        total: { gross: 23, net: 23, currency: "EUR" }
      }
    ) {
      id
    }
  }
}
Running this query requires access tokens. If you have already generated the tokens, you can test out the query using the order API endpoint.

Multiple Items in Cart

The example mutation above only has a single item in the cart. You can add multiple items to the cart as shown below:

cart: [
  {
     name: "New variation"
     sku: "red-headset-564274"
     quantity: 1
     price: {
       currency: "EUR"
       tax: { name: "No Tax", percent: 0 }
       net: 89
       gross: 89
      }
    },
    {
      name: "Adventurous"
      sku: "adventurous-47872"
      quantity: 1
      price: {
        currency: "EUR"
        tax: { name: "No Tax", percent: 0 }
        net: 29
        gross: 29
      }
   }
]
Running this query requires access tokens. If you have already generated the tokens, you can test out the query using the order API endpoint.

Order Metadata

In case you’d like to add more information to your order, such as information about which warehouse the product would be shipped from, you can use the meta field. Data in this field is provided as key-value pairs, as shown below.

meta: {
   key: "Shipped From"
   value: "Warehouse 12"
}
Running this query requires access tokens. If you have already generated the tokens, you can test out the query using the order API endpoint.

Additional Information

The additionalInformation field takes a string value. A good use case for this would be for when a customer makes an additional request while placing an order, such as adding a message to a gift card.

additionalInformation: "Enter your message here!"
Running this query requires access tokens. If you have already generated the tokens, you can test out the query using the order API endpoint.