0
votes

This is my fist time creating an order. From what I understand you need to create a draft order - add products, price, email, notes etc. I am just creating a test query now to see how it works and it tells me "Add at least 1 product". I am trying to add a product, but I dont know how. I have been messing around and reading and cant figure it out.

This is my query:

mutation draftOrderCreate {
  draftOrderCreate(input: {email: "[email protected]"}) {
    draftOrder {
      id
      order {
        id
      }

      status

    }
    
    userErrors {
      field
      message
    }
  }
}

If anyone can give me an example on how to add products to this would be great. Thanks.

1

1 Answers

1
votes

You can create an draft order like so:

mutation draftOrderCreate($items: DraftOrderInput!) {
  draftOrderCreate(input: $items) {
    draftOrder {
      id
      order {
        id
      }
      status
    }
    userErrors {
      field
      message
    }
  }
}

query variables:

{
    "items": {
        "email": "[email protected]",
        "lineItems": [
            {
                "variantId": "gid://shopify/ProductVariant/32231002996788",
                "quantity": 1
            }
        ]
    }
}

Or if you don't want to use query variables you can pass the whole object as the input:

mutation draftOrderCreate {
  draftOrderCreate(input: {email: "[email protected]", lineItems: [{variantId: "gid://shopify/ProductVariant/32231002996788", quantity: 1}]}) {
    draftOrder {
      id
      order {
        id
      }
      status
    }
    userErrors {
      field
      message
    }
  }
}