Version: 2024-01
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation draftOrderCreate($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id } } }\",\n \"variables\": {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\n \"foo\",\n \"bar\"\n ],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"lineItems\": [\n {\n \"title\": \"Custom product\",\n \"originalUnitPrice\": 14.99,\n \"quantity\": 5,\n \"appliedDiscount\": {\n \"description\": \"wholesale\",\n \"value\": 5.0,\n \"amount\": 3.74,\n \"valueType\": \"PERCENTAGE\",\n \"title\": \"Fancy\"\n },\n \"weight\": {\n \"value\": 1,\n \"unit\": \"KILOGRAMS\"\n },\n \"customAttributes\": [\n {\n \"key\": \"color\",\n \"value\": \"Gold\"\n },\n {\n \"key\": \"material\",\n \"value\": \"Plastic\"\n }\n ]\n },\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 2\n }\n ],\n \"customAttributes\": [\n {\n \"key\": \"name\",\n \"value\": \"Achilles\"\n },\n {\n \"key\": \"city\",\n \"value\": \"Troy\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\n \"foo\",\n \"bar\"\n ],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"lineItems\": [\n {\n \"title\": \"Custom product\",\n \"originalUnitPrice\": 14.99,\n \"quantity\": 5,\n \"appliedDiscount\": {\n \"description\": \"wholesale\",\n \"value\": 5.0,\n \"amount\": 3.74,\n \"valueType\": \"PERCENTAGE\",\n \"title\": \"Fancy\"\n },\n \"weight\": {\n \"value\": 1,\n \"unit\": \"KILOGRAMS\"\n },\n \"customAttributes\": [\n {\n \"key\": \"color\",\n \"value\": \"Gold\"\n },\n {\n \"key\": \"material\",\n \"value\": \"Plastic\"\n }\n ]\n },\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 2\n }\n ],\n \"customAttributes\": [\n {\n \"key\": \"name\",\n \"value\": \"Achilles\"\n },\n {\n \"key\": \"city\",\n \"value\": \"Troy\"\n }\n ]\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\"foo\", \"bar\"],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"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}],\n \"customAttributes\": [{\"key\"=>\"name\", \"value\"=>\"Achilles\"}, {\"key\"=>\"city\", \"value\"=>\"Troy\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"customerId\" => \"gid://shopify/Customer/544365967\",\n \"note\" => \"Test draft order\",\n \"email\" => \"test.user@shopify.com\",\n \"taxExempt\" => true,\n \"tags\" => [\"foo\", \"bar\"],\n \"shippingLine\" => [\n \"title\" => \"Custom Shipping\",\n \"price\" => 4.55,\n ],\n \"shippingAddress\" => [\n \"address1\" => \"123 Main St\",\n \"city\" => \"Waterloo\",\n \"province\" => \"Ontario\",\n \"country\" => \"Canada\",\n \"zip\" => \"A1A 1A1\",\n ],\n \"billingAddress\" => [\n \"address1\" => \"456 Main St\",\n \"city\" => \"Toronto\",\n \"province\" => \"Ontario\",\n \"country\" => \"Canada\",\n \"zip\" => \"Z9Z 9Z9\",\n ],\n \"appliedDiscount\" => [\n \"description\" => \"damaged\",\n \"value\" => 5.0,\n \"amount\" => 5.0,\n \"valueType\" => \"FIXED_AMOUNT\",\n \"title\" => \"Custom\",\n ],\n \"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}],\n \"customAttributes\" => [{\"key\"=>\"name\", \"value\"=>\"Achilles\"}, {\"key\"=>\"city\", \"value\"=>\"Troy\"}],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\n \"foo\",\n \"bar\"\n ],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"lineItems\": [\n {\n \"title\": \"Custom product\",\n \"originalUnitPrice\": 14.99,\n \"quantity\": 5,\n \"appliedDiscount\": {\n \"description\": \"wholesale\",\n \"value\": 5.0,\n \"amount\": 3.74,\n \"valueType\": \"PERCENTAGE\",\n \"title\": \"Fancy\"\n },\n \"weight\": {\n \"value\": 1,\n \"unit\": \"KILOGRAMS\"\n },\n \"customAttributes\": [\n {\n \"key\": \"color\",\n \"value\": \"Gold\"\n },\n {\n \"key\": \"material\",\n \"value\": \"Plastic\"\n }\n ]\n },\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 2\n }\n ],\n \"customAttributes\": [\n {\n \"key\": \"name\",\n \"value\": \"Achilles\"\n },\n {\n \"key\": \"city\",\n \"value\": \"Troy\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n }\n}"
input: { "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: { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920476" } } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation draftOrderCreate($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id presentmentCurrencyCode totalPriceSet { shopMoney { amount currencyCode } presentmentMoney { amount currencyCode } } } } }\",\n \"variables\": {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\n \"foo\",\n \"bar\"\n ],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"lineItems\": [\n {\n \"title\": \"Custom product\",\n \"originalUnitPrice\": 14.99,\n \"quantity\": 5,\n \"appliedDiscount\": {\n \"description\": \"wholesale\",\n \"value\": 5.0,\n \"amount\": 3.74,\n \"valueType\": \"PERCENTAGE\",\n \"title\": \"Fancy\"\n },\n \"weight\": {\n \"value\": 1,\n \"unit\": \"KILOGRAMS\"\n },\n \"customAttributes\": [\n {\n \"key\": \"color\",\n \"value\": \"Gold\"\n },\n {\n \"key\": \"material\",\n \"value\": \"Plastic\"\n }\n ]\n },\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 2\n }\n ],\n \"presentmentCurrencyCode\": \"CAD\",\n \"customAttributes\": [\n {\n \"key\": \"name\",\n \"value\": \"Achilles\"\n },\n {\n \"key\": \"city\",\n \"value\": \"Troy\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n presentmentCurrencyCode\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\n \"foo\",\n \"bar\"\n ],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"lineItems\": [\n {\n \"title\": \"Custom product\",\n \"originalUnitPrice\": 14.99,\n \"quantity\": 5,\n \"appliedDiscount\": {\n \"description\": \"wholesale\",\n \"value\": 5.0,\n \"amount\": 3.74,\n \"valueType\": \"PERCENTAGE\",\n \"title\": \"Fancy\"\n },\n \"weight\": {\n \"value\": 1,\n \"unit\": \"KILOGRAMS\"\n },\n \"customAttributes\": [\n {\n \"key\": \"color\",\n \"value\": \"Gold\"\n },\n {\n \"key\": \"material\",\n \"value\": \"Plastic\"\n }\n ]\n },\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 2\n }\n ],\n \"presentmentCurrencyCode\": \"CAD\",\n \"customAttributes\": [\n {\n \"key\": \"name\",\n \"value\": \"Achilles\"\n },\n {\n \"key\": \"city\",\n \"value\": \"Troy\"\n }\n ]\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n presentmentCurrencyCode\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\"foo\", \"bar\"],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"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}],\n \"presentmentCurrencyCode\": \"CAD\",\n \"customAttributes\": [{\"key\"=>\"name\", \"value\"=>\"Achilles\"}, {\"key\"=>\"city\", \"value\"=>\"Troy\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n presentmentCurrencyCode\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"customerId\" => \"gid://shopify/Customer/544365967\",\n \"note\" => \"Test draft order\",\n \"email\" => \"test.user@shopify.com\",\n \"taxExempt\" => true,\n \"tags\" => [\"foo\", \"bar\"],\n \"shippingLine\" => [\n \"title\" => \"Custom Shipping\",\n \"price\" => 4.55,\n ],\n \"shippingAddress\" => [\n \"address1\" => \"123 Main St\",\n \"city\" => \"Waterloo\",\n \"province\" => \"Ontario\",\n \"country\" => \"Canada\",\n \"zip\" => \"A1A 1A1\",\n ],\n \"billingAddress\" => [\n \"address1\" => \"456 Main St\",\n \"city\" => \"Toronto\",\n \"province\" => \"Ontario\",\n \"country\" => \"Canada\",\n \"zip\" => \"Z9Z 9Z9\",\n ],\n \"appliedDiscount\" => [\n \"description\" => \"damaged\",\n \"value\" => 5.0,\n \"amount\" => 5.0,\n \"valueType\" => \"FIXED_AMOUNT\",\n \"title\" => \"Custom\",\n ],\n \"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}],\n \"presentmentCurrencyCode\" => \"CAD\",\n \"customAttributes\" => [{\"key\"=>\"name\", \"value\"=>\"Achilles\"}, {\"key\"=>\"city\", \"value\"=>\"Troy\"}],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n presentmentCurrencyCode\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"customerId\": \"gid://shopify/Customer/544365967\",\n \"note\": \"Test draft order\",\n \"email\": \"test.user@shopify.com\",\n \"taxExempt\": true,\n \"tags\": [\n \"foo\",\n \"bar\"\n ],\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"123 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"A1A 1A1\"\n },\n \"billingAddress\": {\n \"address1\": \"456 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"Z9Z 9Z9\"\n },\n \"appliedDiscount\": {\n \"description\": \"damaged\",\n \"value\": 5.0,\n \"amount\": 5.0,\n \"valueType\": \"FIXED_AMOUNT\",\n \"title\": \"Custom\"\n },\n \"lineItems\": [\n {\n \"title\": \"Custom product\",\n \"originalUnitPrice\": 14.99,\n \"quantity\": 5,\n \"appliedDiscount\": {\n \"description\": \"wholesale\",\n \"value\": 5.0,\n \"amount\": 3.74,\n \"valueType\": \"PERCENTAGE\",\n \"title\": \"Fancy\"\n },\n \"weight\": {\n \"value\": 1,\n \"unit\": \"KILOGRAMS\"\n },\n \"customAttributes\": [\n {\n \"key\": \"color\",\n \"value\": \"Gold\"\n },\n {\n \"key\": \"material\",\n \"value\": \"Plastic\"\n }\n ]\n },\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 2\n }\n ],\n \"presentmentCurrencyCode\": \"CAD\",\n \"customAttributes\": [\n {\n \"key\": \"name\",\n \"value\": \"Achilles\"\n },\n {\n \"key\": \"city\",\n \"value\": \"Troy\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n presentmentCurrencyCode\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n }\n}"
input: { "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 } ], "presentmentCurrencyCode": "CAD", "customAttributes": [ { "key": "name", "value": "Achilles" }, { "key": "city", "value": "Troy" } ] } }
response: { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920495", "presentmentCurrencyCode": "CAD", "totalPriceSet": { "shopMoney": { "amount": "95.29", "currencyCode": "USD" }, "presentmentMoney": { "amount": "119.11", "currencyCode": "CAD" } } } } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation createDraftOrderMetafields($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"delivery_instructions\",\n \"type\": \"single_line_text_field\",\n \"value\": \"leave on back porch\"\n }\n ],\n \"lineItems\": [\n {\n \"title\": \"small wheel\",\n \"quantity\": 1,\n \"originalUnitPrice\": \"10\"\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation createDraftOrderMetafields($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"delivery_instructions\",\n \"type\": \"single_line_text_field\",\n \"value\": \"leave on back porch\"\n }\n ],\n \"lineItems\": [\n {\n \"title\": \"small wheel\",\n \"quantity\": 1,\n \"originalUnitPrice\": \"10\"\n }\n ]\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation createDraftOrderMetafields($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"metafields\": [{\"namespace\"=>\"my_field\", \"key\"=>\"delivery_instructions\", \"type\"=>\"single_line_text_field\", \"value\"=>\"leave on back porch\"}],\n \"lineItems\": [{\"title\"=>\"small wheel\", \"quantity\"=>1, \"originalUnitPrice\"=>\"10\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation createDraftOrderMetafields($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"metafields\" => [{\"namespace\"=>\"my_field\", \"key\"=>\"delivery_instructions\", \"type\"=>\"single_line_text_field\", \"value\"=>\"leave on back porch\"}],\n \"lineItems\" => [{\"title\"=>\"small wheel\", \"quantity\"=>1, \"originalUnitPrice\"=>\"10\"}],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation createDraftOrderMetafields($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"metafields\": [\n {\n \"namespace\": \"my_field\",\n \"key\": \"delivery_instructions\",\n \"type\": \"single_line_text_field\",\n \"value\": \"leave on back porch\"\n }\n ],\n \"lineItems\": [\n {\n \"title\": \"small wheel\",\n \"quantity\": 1,\n \"originalUnitPrice\": \"10\"\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation createDraftOrderMetafields($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n metafields(first: 3) {\n edges {\n node {\n id\n namespace\n key\n value\n }\n }\n }\n }\n userErrors {\n message\n field\n }\n }\n}"
input: { "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: { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920480", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069228934", "namespace": "my_field", "key": "delivery_instructions", "value": "leave on back porch" } } ] } }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation draftOrderCreate($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"purchasingEntity\": {\n \"purchasingCompany\": {\n \"companyId\": \"gid://shopify/Company/426793626\",\n \"companyLocationId\": \"gid://shopify/CompanyLocation/441870438\",\n \"companyContactId\": \"gid://shopify/CompanyContact/207808057\"\n }\n },\n \"note\": \"Test B2B draft order\",\n \"email\": \"test.b2b.user@shopify.com\",\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"555 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"B1B 1B1\"\n },\n \"billingAddress\": {\n \"address1\": \"556 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"D9D DZD\"\n },\n \"lineItems\": [\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 5\n }\n ]\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"purchasingEntity\": {\n \"purchasingCompany\": {\n \"companyId\": \"gid://shopify/Company/426793626\",\n \"companyLocationId\": \"gid://shopify/CompanyLocation/441870438\",\n \"companyContactId\": \"gid://shopify/CompanyContact/207808057\"\n }\n },\n \"note\": \"Test B2B draft order\",\n \"email\": \"test.b2b.user@shopify.com\",\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"555 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"B1B 1B1\"\n },\n \"billingAddress\": {\n \"address1\": \"556 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"D9D DZD\"\n },\n \"lineItems\": [\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 5\n }\n ]\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"purchasingEntity\": {\n \"purchasingCompany\": {\n \"companyId\": \"gid://shopify/Company/426793626\",\n \"companyLocationId\": \"gid://shopify/CompanyLocation/441870438\",\n \"companyContactId\": \"gid://shopify/CompanyContact/207808057\"\n }\n },\n \"note\": \"Test B2B draft order\",\n \"email\": \"test.b2b.user@shopify.com\",\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"555 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"B1B 1B1\"\n },\n \"billingAddress\": {\n \"address1\": \"556 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"D9D DZD\"\n },\n \"lineItems\": [{\"variantId\"=>\"gid://shopify/ProductVariant/43729076\", \"quantity\"=>5}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"purchasingEntity\" => [\n \"purchasingCompany\" => [\n \"companyId\" => \"gid://shopify/Company/426793626\",\n \"companyLocationId\" => \"gid://shopify/CompanyLocation/441870438\",\n \"companyContactId\" => \"gid://shopify/CompanyContact/207808057\",\n ],\n ],\n \"note\" => \"Test B2B draft order\",\n \"email\" => \"test.b2b.user@shopify.com\",\n \"shippingLine\" => [\n \"title\" => \"Custom Shipping\",\n \"price\" => 4.55,\n ],\n \"shippingAddress\" => [\n \"address1\" => \"555 Main St\",\n \"city\" => \"Waterloo\",\n \"province\" => \"Ontario\",\n \"country\" => \"Canada\",\n \"zip\" => \"B1B 1B1\",\n ],\n \"billingAddress\" => [\n \"address1\" => \"556 Main St\",\n \"city\" => \"Toronto\",\n \"province\" => \"Ontario\",\n \"country\" => \"Canada\",\n \"zip\" => \"D9D DZD\",\n ],\n \"lineItems\" => [{\"variantId\"=>\"gid://shopify/ProductVariant/43729076\", \"quantity\"=>5}],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"purchasingEntity\": {\n \"purchasingCompany\": {\n \"companyId\": \"gid://shopify/Company/426793626\",\n \"companyLocationId\": \"gid://shopify/CompanyLocation/441870438\",\n \"companyContactId\": \"gid://shopify/CompanyContact/207808057\"\n }\n },\n \"note\": \"Test B2B draft order\",\n \"email\": \"test.b2b.user@shopify.com\",\n \"shippingLine\": {\n \"title\": \"Custom Shipping\",\n \"price\": 4.55\n },\n \"shippingAddress\": {\n \"address1\": \"555 Main St\",\n \"city\": \"Waterloo\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"B1B 1B1\"\n },\n \"billingAddress\": {\n \"address1\": \"556 Main St\",\n \"city\": \"Toronto\",\n \"province\": \"Ontario\",\n \"country\": \"Canada\",\n \"zip\": \"D9D DZD\"\n },\n \"lineItems\": [\n {\n \"variantId\": \"gid://shopify/ProductVariant/43729076\",\n \"quantity\": 5\n }\n ]\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n}"
input: { "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: { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920484" }, "userErrors": [] } } }
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation draftOrderCreate($input: DraftOrderInput!) { draftOrderCreate(input: $input) { draftOrder { id } userErrors { message field } } }\",\n \"variables\": {\n \"input\": {\n \"lineItems\": []\n }\n }\n}'\n" Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"input\": {\n \"lineItems\": []\n }\n },\n },\n});\n" Ruby example: "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"lineItems\": []\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n" PHP example: "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"lineItems\" => [],\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"input\": {\n \"lineItems\": []\n }\n },\n },\n);\n\nconst data = await response.json();\n" Graphql query: "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n}"
input: { "input": { "lineItems": [] } }
response: { "data": { "draftOrderCreate": { "draftOrder": null, "userErrors": [ { "message": "Add at least 1 product", "field": null } ] } } }