Create a draft order
Description
Create a draft order that combines custom line items with existing products from your store.
This example demonstrates creating custom products with manual pricing alongside actual products from your store inventory, using the [`appliedDiscount`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/draftOrderCreate#arguments-input.fields.appliedDiscount) field at both the order level and line-item level.
Learn more about [custom attributes](https://shopify.dev/docs/apps/build/custom-data/metafields/manage-metafields).
Query
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
}
}
Variables
{
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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"
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-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": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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"
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
}
}`,
{
variables: {
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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 json = await response.json();
return json.data;
}
Ruby
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": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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)
Node.js
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": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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
{
"draftOrderCreate": {
"draftOrder": {
"id": "gid://shopify/DraftOrder/1069920508"
}
}
}
Create a draft order with line item components
Description
Creates a draft order with a line item that has components
Query
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
lineItems(first: 100) {
edges {
node {
id
components {
id
}
}
}
}
}
}
}
Variables
{
"input": {
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/799757249",
"quantity": 1,
"components": [
{
"variantId": "gid://shopify/ProductVariant/149896808",
"quantity": 1
},
{
"variantId": "gid://shopify/ProductVariant/709406719",
"quantity": 1
}
]
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-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 lineItems(first: 100) { edges { node { id components { id } } } } } } }",
"variables": {
"input": {
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/799757249",
"quantity": 1,
"components": [
{
"variantId": "gid://shopify/ProductVariant/149896808",
"quantity": 1
},
{
"variantId": "gid://shopify/ProductVariant/709406719",
"quantity": 1
}
]
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
lineItems(first: 100) {
edges {
node {
id
components {
id
}
}
}
}
}
}
}`,
{
variables: {
"input": {
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/799757249",
"quantity": 1,
"components": [
{
"variantId": "gid://shopify/ProductVariant/149896808",
"quantity": 1
},
{
"variantId": "gid://shopify/ProductVariant/709406719",
"quantity": 1
}
]
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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
lineItems(first: 100) {
edges {
node {
id
components {
id
}
}
}
}
}
}
}
QUERY
variables = {
"input": {
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/799757249",
"quantity": 1,
"components": [
{
"variantId": "gid://shopify/ProductVariant/149896808",
"quantity": 1
},
{
"variantId": "gid://shopify/ProductVariant/709406719",
"quantity": 1
}
]
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
lineItems(first: 100) {
edges {
node {
id
components {
id
}
}
}
}
}
}
}`,
"variables": {
"input": {
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/799757249",
"quantity": 1,
"components": [
{
"variantId": "gid://shopify/ProductVariant/149896808",
"quantity": 1
},
{
"variantId": "gid://shopify/ProductVariant/709406719",
"quantity": 1
}
]
}
]
}
},
},
});
Response
{
"draftOrderCreate": {
"draftOrder": {
"id": "gid://shopify/DraftOrder/1069920512",
"lineItems": {
"edges": [
{
"node": {
"id": "gid://shopify/DraftOrderLineItem/1066630446",
"components": [
{
"id": "gid://shopify/DraftOrderLineItem/1066630447"
},
{
"id": "gid://shopify/DraftOrderLineItem/1066630448"
}
]
}
}
]
}
}
}
}
Create a draft order with presentment currency
Description
Create a comprehensive draft order with presentment currency, discounts, custom products, and custom attributes.
This example demonstrates setting a customer-facing currency (CAD), mixing custom line-items with existing store products, and adding custom attributes at both order and line-item levels.
The [`totalPriceSet`](https://shopify.dev/docs/api/admin-graphql/latest/objects/DraftOrder#field-DraftOrder.fields.totalPriceSet) field returns pricing in both shop and presentment currencies.
Learn more about [presentment currencies](https://help.shopify.com/manual/international/pricing/exchange-rates).
Query
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
presentmentCurrencyCode
totalPriceSet {
shopMoney {
amount
currencyCode
}
presentmentMoney {
amount
currencyCode
}
}
}
}
}
Variables
{
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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
}
],
"presentmentCurrencyCode": "CAD",
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-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 presentmentCurrencyCode totalPriceSet { shopMoney { amount currencyCode } presentmentMoney { amount currencyCode } } } } }",
"variables": {
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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
}
],
"presentmentCurrencyCode": "CAD",
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
presentmentCurrencyCode
totalPriceSet {
shopMoney {
amount
currencyCode
}
presentmentMoney {
amount
currencyCode
}
}
}
}
}`,
{
variables: {
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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
}
],
"presentmentCurrencyCode": "CAD",
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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
presentmentCurrencyCode
totalPriceSet {
shopMoney {
amount
currencyCode
}
presentmentMoney {
amount
currencyCode
}
}
}
}
}
QUERY
variables = {
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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
}
],
"presentmentCurrencyCode": "CAD",
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
presentmentCurrencyCode
totalPriceSet {
shopMoney {
amount
currencyCode
}
presentmentMoney {
amount
currencyCode
}
}
}
}
}`,
"variables": {
"input": {
"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,
"amount": 5,
"valueType": "FIXED_AMOUNT",
"title": "Custom"
},
"lineItems": [
{
"title": "Custom product",
"originalUnitPrice": 14.99,
"quantity": 5,
"appliedDiscount": {
"description": "wholesale",
"value": 5,
"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
}
],
"presentmentCurrencyCode": "CAD",
"customAttributes": [
{
"key": "name",
"value": "Achilles"
},
{
"key": "city",
"value": "Troy"
}
]
}
},
},
});
Response
{
"draftOrderCreate": {
"draftOrder": {
"id": "gid://shopify/DraftOrder/1069920514",
"presentmentCurrencyCode": "CAD",
"totalPriceSet": {
"shopMoney": {
"amount": "95.29",
"currencyCode": "USD"
},
"presentmentMoney": {
"amount": "119.11",
"currencyCode": "CAD"
}
}
}
}
}
Create a new metafield on a new draft order
Description
Create a draft order with custom [metafields](https://shopify.dev/docs/api/admin-graphql/latest/objects/DraftOrder#field-DraftOrder.fields.metafields) for storing delivery instructions.
This example demonstrates adding structured metadata to draft orders for operational information that doesn't fit standard order fields, such as special delivery instructions, internal notes,
or custom fulfillment requirements.
Alternatively, refer to the [`metafieldsSet`](https://shopify.dev/docs/api/admin-graphql/latest/mutations/metafieldsset) mutation
to create or update metafields on draft orders.
Query
mutation createDraftOrderMetafields($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
Variables
{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
}
],
"lineItems": [
{
"title": "small wheel",
"quantity": 1,
"originalUnitPrice": "10"
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation createDraftOrderMetafields($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
}
],
"lineItems": [
{
"title": "small wheel",
"quantity": 1,
"originalUnitPrice": "10"
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createDraftOrderMetafields($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
}
],
"lineItems": [
{
"title": "small wheel",
"quantity": 1,
"originalUnitPrice": "10"
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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 createDraftOrderMetafields($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
}
],
"lineItems": [
{
"title": "small wheel",
"quantity": 1,
"originalUnitPrice": "10"
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createDraftOrderMetafields($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
}
],
"lineItems": [
{
"title": "small wheel",
"quantity": 1,
"originalUnitPrice": "10"
}
]
}
},
},
});
Response
{
"draftOrderCreate": {
"draftOrder": {
"id": "gid://shopify/DraftOrder/1069920509",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069228940",
"namespace": "my_field",
"key": "delivery_instructions",
"value": "leave on back porch"
}
}
]
}
},
"userErrors": []
}
}
Creating a draft order with a company, location and company contact
Description
Create a B2B draft order with a [`purchasingEntity`](https://shopify.dev/docs/api/admin-graphql/latest/objects/DraftOrder#field-DraftOrder.fields.purchasingEntity).
This example demonstrates orders for wholesale customers, corporate accounts, or business
partners where the buyer represents a company rather than an individual customer. Learn more about [building B2B draft orders](https://shopify.dev/docs/apps/build/b2b/draft-orders).
Query
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
userErrors {
message
field
}
}
}
Variables
{
"input": {
"purchasingEntity": {
"purchasingCompany": {
"companyId": "gid://shopify/Company/426793626",
"companyLocationId": "gid://shopify/CompanyLocation/441870438",
"companyContactId": "gid://shopify/CompanyContact/207808057"
}
},
"note": "Test B2B draft order",
"email": "test.b2b.user@shopify.com",
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "555 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "B1B 1B1"
},
"billingAddress": {
"address1": "556 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "D9D DZD"
},
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 5
}
]
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-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 } userErrors { message field } } }",
"variables": {
"input": {
"purchasingEntity": {
"purchasingCompany": {
"companyId": "gid://shopify/Company/426793626",
"companyLocationId": "gid://shopify/CompanyLocation/441870438",
"companyContactId": "gid://shopify/CompanyContact/207808057"
}
},
"note": "Test B2B draft order",
"email": "test.b2b.user@shopify.com",
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "555 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "B1B 1B1"
},
"billingAddress": {
"address1": "556 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "D9D DZD"
},
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 5
}
]
}
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"purchasingEntity": {
"purchasingCompany": {
"companyId": "gid://shopify/Company/426793626",
"companyLocationId": "gid://shopify/CompanyLocation/441870438",
"companyContactId": "gid://shopify/CompanyContact/207808057"
}
},
"note": "Test B2B draft order",
"email": "test.b2b.user@shopify.com",
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "555 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "B1B 1B1"
},
"billingAddress": {
"address1": "556 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "D9D DZD"
},
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 5
}
]
}
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"purchasingEntity": {
"purchasingCompany": {
"companyId": "gid://shopify/Company/426793626",
"companyLocationId": "gid://shopify/CompanyLocation/441870438",
"companyContactId": "gid://shopify/CompanyContact/207808057"
}
},
"note": "Test B2B draft order",
"email": "test.b2b.user@shopify.com",
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "555 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "B1B 1B1"
},
"billingAddress": {
"address1": "556 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "D9D DZD"
},
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 5
}
]
}
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"purchasingEntity": {
"purchasingCompany": {
"companyId": "gid://shopify/Company/426793626",
"companyLocationId": "gid://shopify/CompanyLocation/441870438",
"companyContactId": "gid://shopify/CompanyContact/207808057"
}
},
"note": "Test B2B draft order",
"email": "test.b2b.user@shopify.com",
"shippingLine": {
"title": "Custom Shipping",
"price": 4.55
},
"shippingAddress": {
"address1": "555 Main St",
"city": "Waterloo",
"province": "Ontario",
"country": "Canada",
"zip": "B1B 1B1"
},
"billingAddress": {
"address1": "556 Main St",
"city": "Toronto",
"province": "Ontario",
"country": "Canada",
"zip": "D9D DZD"
},
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/43729076",
"quantity": 5
}
]
}
},
},
});
Response
{
"draftOrderCreate": {
"draftOrder": {
"id": "gid://shopify/DraftOrder/1069920513"
},
"userErrors": []
}
}