Anchor to section titled 'undefined'

draftOrderCreate
mutation

Requires write_draft_orders access scope. Also: The user must have access to manage draft orders.

Creates a draft order.


The fields used to create the draft order.


Was this section helpful?

The created draft order.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation draftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-07/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();
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)
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"
          }
        ]
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);
Hide code
Input variables
Copy
{
  "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,
      "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"
      }
    ]
  }
}
Hide code
Response
JSON
{
  "draftOrderCreate": {
    "draftOrder": {
      "id": "gid://shopify/DraftOrder/1069920477"
    }
  }
}