draft Order Createmutation
mutation
2024-10latest
Requires write
access scope. Also: The user must have access to manage draft orders.
Creates a draft order.
Arguments
The fields used to create the draft order.
Was this section helpful?
DraftOrderCreatePayload returns
The created draft order.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: draftOrderCreate
Query Reference for MUTATION: draftOrderCreate
"mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n # DraftOrder fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: draftOrderCreate
"{\n \"input\": {\n \"acceptAutomaticDiscounts\": true,\n \"allowDiscountCodesInCheckout\": true,\n \"appliedDiscount\": {\n \"amount\": \"100.57\",\n \"amountWithCurrency\": {\n \"amount\": \"29.99\",\n \"currencyCode\": \"AED\"\n },\n \"description\": \"<your-description>\",\n \"title\": \"<your-title>\",\n \"value\": 1.1,\n \"valueType\": \"FIXED_AMOUNT\"\n },\n \"billingAddress\": {\n \"address1\": \"<your-address1>\",\n \"address2\": \"<your-address2>\",\n \"city\": \"<your-city>\",\n \"company\": \"<your-company>\",\n \"country\": \"<your-country>\",\n \"countryCode\": \"AC\",\n \"firstName\": \"<your-firstName>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"lastName\": \"<your-lastName>\",\n \"phone\": \"<your-phone>\",\n \"province\": \"<your-province>\",\n \"provinceCode\": \"<your-provinceCode>\",\n \"zip\": \"<your-zip>\"\n },\n \"customAttributes\": [\n {\n \"key\": \"<your-key>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"discountCodes\": [\n \"<your-discountCodes>\"\n ],\n \"email\": \"<your-email>\",\n \"lineItems\": [\n {\n \"appliedDiscount\": {\n \"amountWithCurrency\": {\n \"amount\": \"29.99\",\n \"currencyCode\": \"AED\"\n },\n \"description\": \"<your-description>\",\n \"title\": \"<your-title>\",\n \"value\": 1.1,\n \"valueType\": \"FIXED_AMOUNT\"\n },\n \"bundleComponents\": [\n {\n \"quantity\": 1,\n \"uuid\": \"<your-uuid>\",\n \"variantId\": \"gid://shopify/<objectName>/10079785100\"\n }\n ],\n \"customAttributes\": [\n {\n \"key\": \"<your-key>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"grams\": 1,\n \"originalUnitPrice\": \"100.57\",\n \"originalUnitPriceWithCurrency\": {\n \"amount\": \"29.99\",\n \"currencyCode\": \"AED\"\n },\n \"quantity\": 1,\n \"requiresShipping\": true,\n \"sku\": \"<your-sku>\",\n \"taxable\": true,\n \"title\": \"<your-title>\",\n \"uuid\": \"<your-uuid>\",\n \"variantId\": \"gid://shopify/<objectName>/10079785100\",\n \"weight\": {\n \"unit\": \"GRAMS\",\n \"value\": 1.1\n }\n }\n ],\n \"localizationExtensions\": [\n {\n \"key\": \"SHIPPING_CREDENTIAL_BR\",\n \"value\": \"<your-value>\"\n }\n ],\n \"marketRegionCountryCode\": \"AC\",\n \"metafields\": [\n {\n \"description\": \"<your-description>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"key\": \"<your-key>\",\n \"namespace\": \"<your-namespace>\",\n \"type\": \"<your-type>\",\n \"value\": \"<your-value>\"\n }\n ],\n \"note\": \"<your-note>\",\n \"paymentTerms\": {\n \"paymentSchedules\": [\n {\n \"dueAt\": \"2019-09-07T15:50:00Z\",\n \"issuedAt\": \"2019-09-07T15:50:00Z\"\n }\n ],\n \"paymentTermsTemplateId\": \"gid://shopify/<objectName>/10079785100\"\n },\n \"phone\": \"<your-phone>\",\n \"poNumber\": \"<your-poNumber>\",\n \"presentmentCurrencyCode\": \"AED\",\n \"purchasingEntity\": {\n \"customerId\": \"gid://shopify/<objectName>/10079785100\",\n \"purchasingCompany\": {\n \"companyContactId\": \"gid://shopify/<objectName>/10079785100\",\n \"companyId\": \"gid://shopify/<objectName>/10079785100\",\n \"companyLocationId\": \"gid://shopify/<objectName>/10079785100\"\n }\n },\n \"reserveInventoryUntil\": \"2019-09-07T15:50:00Z\",\n \"sessionToken\": \"<your-sessionToken>\",\n \"shippingAddress\": {\n \"address1\": \"<your-address1>\",\n \"address2\": \"<your-address2>\",\n \"city\": \"<your-city>\",\n \"company\": \"<your-company>\",\n \"country\": \"<your-country>\",\n \"countryCode\": \"AC\",\n \"firstName\": \"<your-firstName>\",\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"lastName\": \"<your-lastName>\",\n \"phone\": \"<your-phone>\",\n \"province\": \"<your-province>\",\n \"provinceCode\": \"<your-provinceCode>\",\n \"zip\": \"<your-zip>\"\n },\n \"shippingLine\": {\n \"price\": \"100.57\",\n \"priceWithCurrency\": {\n \"amount\": \"29.99\",\n \"currencyCode\": \"AED\"\n },\n \"shippingRateHandle\": \"<your-shippingRateHandle>\",\n \"title\": \"<your-title>\"\n },\n \"sourceName\": \"<your-sourceName>\",\n \"tags\": [\n \"<your-tags>\"\n ],\n \"taxExempt\": true,\n \"transformerFingerprint\": \"<your-transformerFingerprint>\",\n \"useCustomerDefaultAddress\": true,\n \"visibleToCustomer\": true\n }\n}"
Schema Reference for MUTATION: draftOrderCreate
"input DraftOrderInput {\n acceptAutomaticDiscounts: Boolean\n allowDiscountCodesInCheckout: Boolean\n appliedDiscount: DraftOrderAppliedDiscountInput\n billingAddress: MailingAddressInput\n customAttributes: [AttributeInput!]\n customerId: ID\n discountCodes: [String!]\n email: String\n lineItems: [DraftOrderLineItemInput!]\n localizationExtensions: [LocalizationExtensionInput!]\n marketRegionCountryCode: CountryCode\n metafields: [MetafieldInput!]\n note: String\n paymentTerms: PaymentTermsInput\n phone: String\n poNumber: String\n presentmentCurrencyCode: CurrencyCode\n privateMetafields: [PrivateMetafieldInput!]\n purchasingEntity: PurchasingEntityInput\n reserveInventoryUntil: DateTime\n sessionToken: String\n shippingAddress: MailingAddressInput\n shippingLine: ShippingLineInput\n sourceName: String\n tags: [String!]\n taxExempt: Boolean\n transformerFingerprint: String\n useCustomerDefaultAddress: Boolean\n visibleToCustomer: Boolean\n}\n\ninput DraftOrderAppliedDiscountInput {\n amount: Money\n amountWithCurrency: MoneyInput\n description: String\n title: String\n value: Float!\n valueType: DraftOrderAppliedDiscountType!\n}\n\ninput MailingAddressInput {\n address1: String\n address2: String\n city: String\n company: String\n country: String\n countryCode: CountryCode\n firstName: String\n id: ID\n lastName: String\n phone: String\n province: String\n provinceCode: String\n zip: String\n}\n\ninput AttributeInput {\n key: String!\n value: String!\n}\n\ninput DraftOrderLineItemInput {\n appliedDiscount: DraftOrderAppliedDiscountInput\n bundleComponents: [BundlesDraftOrderBundleLineItemComponentInput!]\n customAttributes: [AttributeInput!]\n grams: Int\n originalUnitPrice: Money\n originalUnitPriceWithCurrency: MoneyInput\n quantity: Int!\n requiresShipping: Boolean\n sku: String\n taxable: Boolean\n title: String\n uuid: String\n variantId: ID\n weight: WeightInput\n}\n\ninput LocalizationExtensionInput {\n key: LocalizationExtensionKey!\n value: String!\n}\n\ninput MetafieldInput {\n description: String\n id: ID\n key: String\n namespace: String\n type: String\n value: String\n}\n\ninput PaymentTermsInput {\n paymentSchedules: [PaymentScheduleInput!]\n paymentTermsTemplateId: ID\n}\n\ninput PrivateMetafieldInput {\n key: String!\n namespace: String!\n owner: ID\n valueInput: PrivateMetafieldValueInput!\n}\n\ninput PurchasingEntityInput {\n customerId: ID\n purchasingCompany: PurchasingCompanyInput\n}\n\ninput ShippingLineInput {\n price: Money\n priceWithCurrency: MoneyInput\n shippingRateHandle: String\n title: String\n}\n"
Display Examples for MUTATION: draftOrderCreate
[ { "example": { "type_name": "draftordercreate", "title": "Create a draft order", "description": "Creates a draft order with shippingLine, shipping and billing addresses,appliedDiscount, lineItems, and custom attributes", "query_string": "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n }\n}", "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, "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": { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920477" } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_create_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/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", "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", "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", "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", "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" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The fields used to create the draft order.", "type": { "kind": "INPUT_OBJECT", "name": "DraftOrderInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DraftOrderInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"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\"}]}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "draftordercreate", "title": "Create a draft order with markets context", "description": "Creates a multi-currency draft order with shippingLine, shipping and billing addresses,appliedDiscount, lineItems, and custom attributes in context of specified market", "query_string": "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n marketName\n marketRegionCountryCode\n presentmentCurrencyCode\n totalPriceSet {\n shopMoney {\n amount\n currencyCode\n }\n presentmentMoney {\n amount\n currencyCode\n }\n }\n }\n }\n}", "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, "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 } ], "marketRegionCountryCode": "CA", "presentmentCurrencyCode": "CAD", "customAttributes": [ { "key": "name", "value": "Achilles" }, { "key": "city", "value": "Troy" } ] } }, "response": { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920475", "marketName": "Primary market", "marketRegionCountryCode": "CA", "presentmentCurrencyCode": "CAD", "totalPriceSet": { "shopMoney": { "amount": "95.29", "currencyCode": "USD" }, "presentmentMoney": { "amount": "119.11", "currencyCode": "CAD" } } } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_create_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/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 marketName marketRegionCountryCode 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 \"marketRegionCountryCode\": \"CA\",\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", "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 marketName\n marketRegionCountryCode\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 \"marketRegionCountryCode\": \"CA\",\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", "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 marketName\n marketRegionCountryCode\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 \"marketRegionCountryCode\": \"CA\",\n \"presentmentCurrencyCode\": \"CAD\",\n \"customAttributes\": [{\"key\"=>\"name\", \"value\"=>\"Achilles\"}, {\"key\"=>\"city\", \"value\"=>\"Troy\"}]\n }\n}\n\nresponse = client.query(query: query, variables: variables)\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 marketName\n marketRegionCountryCode\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 \"marketRegionCountryCode\": \"CA\",\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", "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 marketName\n marketRegionCountryCode\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 \"marketRegionCountryCode\" => \"CA\",\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" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The fields used to create the draft order.", "type": { "kind": "INPUT_OBJECT", "name": "DraftOrderInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DraftOrderInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"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}],\"marketRegionCountryCode\":\"CA\",\"presentmentCurrencyCode\":\"CAD\",\"customAttributes\":[{\"key\":\"name\",\"value\":\"Achilles\"},{\"key\":\"city\",\"value\":\"Troy\"}]}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "draftordercreate", "title": "Create a new metafield on a new draft order", "description": "Create a new metafield `my_field.delivery_instructions` on a new\ndraft order.\n\n\nAlternatively, refer to the\n[metafieldsSet](https://shopify.dev/api/admin-graphql/latest/mutations/metafieldsset) mutation\nto create and/or update metafields on draft order resources.\n", "query_string": "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}", "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": { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920478", "metafields": { "edges": [ { "node": { "id": "gid://shopify/Metafield/1069228947", "namespace": "my_field", "key": "delivery_instructions", "value": "leave on back porch" } } ] } }, "userErrors": [] } } }, "api_name": "admin", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_create_test.rb", "minimum_api_version": null, "maximum_api_version": null, "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/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", "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", "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", "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", "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" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The fields used to create the draft order.", "type": { "kind": "INPUT_OBJECT", "name": "DraftOrderInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DraftOrderInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"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\"}]}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "draftordercreate", "title": "Creating a draft order with a company, location and company contact", "description": "Creates a draft order with a company as the customer, with an associated location and company contact. This is also refered to as a B2B draft order.", "query_string": "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n}", "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": { "data": { "draftOrderCreate": { "draftOrder": { "id": "gid://shopify/DraftOrder/1069920476" }, "userErrors": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_create_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/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", "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", "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", "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", "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" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The fields used to create the draft order.", "type": { "kind": "INPUT_OBJECT", "name": "DraftOrderInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DraftOrderInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"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}]}", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "draftordercreate", "title": "Creating a draft order with invalid input returns an error", "query_string": "mutation draftOrderCreate($input: DraftOrderInput!) {\n draftOrderCreate(input: $input) {\n draftOrder {\n id\n }\n userErrors {\n message\n field\n }\n }\n}", "variables": { "input": { "lineItems": [] } }, "response": { "data": { "draftOrderCreate": { "draftOrder": null, "userErrors": [ { "message": "Add at least 1 product", "field": null } ] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_create_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/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 }\n}'\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 },\n);\n\nconst data = await response.json();\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", "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 },\n});\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" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The fields used to create the draft order.", "type": { "kind": "INPUT_OBJECT", "name": "DraftOrderInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "DraftOrderInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"lineItems\":[]}", "typeKind": "MUTATION" } ] } ]