Anchor to draftOrderCreatedraft
draftOrderCreate
mutation
Requires access scope. Also: The user must have access to manage draft orders.
Creates a draft order.
Anchor to Arguments
Arguments
- Anchor to inputinput•Draft
Order requiredInput! The fields used to create the draft order.
Was this section helpful?
Anchor to DraftOrderCreatePayload returnsDraftOrderCreatePayload returns
- Anchor to draftOrderdraft•
Order The created draft order.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a draft order
- Create a draft order with markets context
- Create a new metafield on a new draft order
- Creating a draft order with a company, location and company contact
- Creating a draft order with invalid input returns an error
- draftOrderCreate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation draftOrderCreate($input: DraftOrderInput!) {6 draftOrderCreate(input: $input) {7 draftOrder {8 id9 }10 }11 }`,12 {13 variables: {14 "input": {15 "customerId": "gid://shopify/Customer/544365967",16 "note": "Test draft order",17 "email": "test.user@shopify.com",18 "taxExempt": true,19 "tags": [20 "foo",21 "bar"22 ],23 "shippingLine": {24 "title": "Custom Shipping",25 "price": 4.5526 },27 "shippingAddress": {28 "address1": "123 Main St",29 "city": "Waterloo",30 "province": "Ontario",31 "country": "Canada",32 "zip": "A1A 1A1"33 },34 "billingAddress": {35 "address1": "456 Main St",36 "city": "Toronto",37 "province": "Ontario",38 "country": "Canada",39 "zip": "Z9Z 9Z9"40 },41 "appliedDiscount": {42 "description": "damaged",43 "value": 5.0,44 "amount": 5.0,45 "valueType": "FIXED_AMOUNT",46 "title": "Custom"47 },48 "lineItems": [49 {50 "title": "Custom product",51 "originalUnitPrice": 14.99,52 "quantity": 5,53 "appliedDiscount": {54 "description": "wholesale",55 "value": 5.0,56 "amount": 3.74,57 "valueType": "PERCENTAGE",58 "title": "Fancy"59 },60 "weight": {61 "value": 1,62 "unit": "KILOGRAMS"63 },64 "customAttributes": [65 {66 "key": "color",67 "value": "Gold"68 },69 {70 "key": "material",71 "value": "Plastic"72 }73 ]74 },75 {76 "variantId": "gid://shopify/ProductVariant/43729076",77 "quantity": 278 }79 ],80 "customAttributes": [81 {82 "key": "name",83 "value": "Achilles"84 },85 {86 "key": "city",87 "value": "Troy"88 }89 ]90 }91 },92 },93);9495const data = await response.json();96
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation draftOrderCreate($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id } } }",
"variables": {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"note": "Test draft order",
"email": "test.user@shopify.com",
"taxExempt": true,
"tags": [
"foo",
"bar"
],
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "123 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "A1A 1A1"
},
"billingAddress": {
"address1": "456 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "Z9Z 9Z9"
},
"appliedDiscount": {
"description": "damaged",
"value": 5.0,
"amount": 5.0,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5.0,
"amount": 3.74,
"valueType": "PERCENTAGE",
"title": "Fancy"
},
"weight": {
"value": 1,
"unit": "KILOGRAMS"
},
"customAttributes": [
{
"key": "color",
"value": "Gold"
},
{
"key": "material",
"value": "Plastic"
}
]
},
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 2
}
],
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
}
}`,
{
variables: {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"note": "Test draft order",
"email": "test.user@shopify.com",
"taxExempt": true,
"tags": [
"foo",
"bar"
],
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "123 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "A1A 1A1"
},
"billingAddress": {
"address1": "456 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "Z9Z 9Z9"
},
"appliedDiscount": {
"description": "damaged",
"value": 5.0,
"amount": 5.0,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5.0,
"amount": 3.74,
"valueType": "PERCENTAGE",
"title": "Fancy"
},
"weight": {
"value": 1,
"unit": "KILOGRAMS"
},
"customAttributes": [
{
"key": "color",
"value": "Gold"
},
{
"key": "material",
"value": "Plastic"
}
]
},
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 2
}
],
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
}
}`,
"variables": {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"note": "Test draft order",
"email": "test.user@shopify.com",
"taxExempt": true,
"tags": [
"foo",
"bar"
],
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "123 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "A1A 1A1"
},
"billingAddress": {
"address1": "456 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "Z9Z 9Z9"
},
"appliedDiscount": {
"description": "damaged",
"value": 5.0,
"amount": 5.0,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5.0,
"amount": 3.74,
"valueType": "PERCENTAGE",
"title": "Fancy"
},
"weight": {
"value": 1,
"unit": "KILOGRAMS"
},
"customAttributes": [
{
"key": "color",
"value": "Gold"
},
{
"key": "material",
"value": "Plastic"
}
]
},
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 2
}
],
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
}
}
QUERY
variables = {
"input": {
"customerId": "gid://shopify/Customer/544365967",
"note": "Test draft order",
"email": "test.user@shopify.com",
"taxExempt": true,
"tags": ["foo", "bar"],
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "123 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "A1A 1A1"
},
"billingAddress": {
"address1": "456 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "Z9Z 9Z9"
},
"appliedDiscount": {
"description": "damaged",
"value": 5.0,
"amount": 5.0,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [{"title"=>"Custom product", "originalUnitPrice"=>14.99, "quantity"=>5, "appliedDiscount"=>{"description"=>"wholesale", "value"=>5.0, "amount"=>3.74, "valueType"=>"PERCENTAGE", "title"=>"Fancy"}, "weight"=>{"value"=>1, "unit"=>"KILOGRAMS"}, "customAttributes"=>[{"key"=>"color", "value"=>"Gold"}, {"key"=>"material", "value"=>"Plastic"}]}, {"variantId"=>"gid://shopify/ProductVariant/43729076", "quantity"=>2}],
"customAttributes": [{"key"=>"name", "value"=>"Achilles"}, {"key"=>"city", "value"=>"Troy"}]
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "input": {3 "customerId": "gid://shopify/Customer/544365967",4 "note": "Test draft order",5 "email": "test.user@shopify.com",6 "taxExempt": true,7 "tags": [8 "foo",9 "bar"10 ],11 "shippingLine": {12 "title": "Custom Shipping",13 "price": 4.5514 },15 "shippingAddress": {16 "address1": "123 Main St",17 "city": "Waterloo",18 "province": "Ontario",19 "country": "Canada",20 "zip": "A1A 1A1"21 },22 "billingAddress": {23 "address1": "456 Main St",24 "city": "Toronto",25 "province": "Ontario",26 "country": "Canada",27 "zip": "Z9Z 9Z9"28 },29 "appliedDiscount": {30 "description": "damaged",31 "value": 5,32 "amount": 5,33 "valueType": "FIXED_AMOUNT",34 "title": "Custom"35 },36 "lineItems": [37 {38 "title": "Custom product",39 "originalUnitPrice": 14.99,40 "quantity": 5,41 "appliedDiscount": {42 "description": "wholesale",43 "value": 5,44 "amount": 3.74,45 "valueType": "PERCENTAGE",46 "title": "Fancy"47 },48 "weight": {49 "value": 1,50 "unit": "KILOGRAMS"51 },52 "customAttributes": [53 {54 "key": "color",55 "value": "Gold"56 },57 {58 "key": "material",59 "value": "Plastic"60 }61 ]62 },63 {64 "variantId": "gid://shopify/ProductVariant/43729076",65 "quantity": 266 }67 ],68 "customAttributes": [69 {70 "key": "name",71 "value": "Achilles"72 },73 {74 "key": "city",75 "value": "Troy"76 }77 ]78 }79}
Response
JSON1{2 "draftOrderCreate": {3 "draftOrder": {4 "id": "gid://shopify/DraftOrder/1069920527"5 }6 }7}