draft Order Completemutation
mutation
2024-10latest
Requires write
access scope. Also: The user must have access to mark as paid, or set payment terms.
Completes a draft order and creates an order.
Arguments
The draft order to complete.
Anchor to paymentGatewayIdpaymentGatewayIdThe gateway for the completed draft order.
Anchor to sourceNamesourceNameA channel definition handle used for sales channel attribution.
Was this section helpful?
DraftOrderCompletePayload returns
The completed draft order.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: draftOrderComplete
Query Reference for MUTATION: draftOrderComplete
"mutation draftOrderComplete($id: ID!) {\n draftOrderComplete(id: $id) {\n draftOrder {\n # DraftOrder fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: draftOrderComplete
"{\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"paymentGatewayId\": \"gid://shopify/<objectName>/10079785100\",\n \"paymentPending\": true,\n \"sourceName\": \"<your-sourceName>\"\n}"
Schema Reference for MUTATION: draftOrderComplete
""
Display Examples for MUTATION: draftOrderComplete
[ { "example": { "type_name": "draftordercomplete", "title": "Complete a draft order", "description": "Completes a draft order and creates an order. If no payment gateway is provided, then the default gateway is used. Returns the new order ID.", "query_string": "mutation draftOrderComplete($id: ID!) {\n draftOrderComplete(id: $id) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n}", "variables": { "id": "gid://shopify/DraftOrder/276395349" }, "response": { "data": { "draftOrderComplete": { "draftOrder": { "id": "gid://shopify/DraftOrder/276395349", "order": { "id": "gid://shopify/Order/1073459966" } } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_complete_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 draftOrderComplete($id: ID!) { draftOrderComplete(id: $id) { draftOrder { id order { id } } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/DraftOrder/276395349\"\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderComplete($id: ID!) {\n draftOrderComplete(id: $id) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/DraftOrder/276395349\"\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 draftOrderComplete($id: ID!) {\n draftOrderComplete(id: $id) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/DraftOrder/276395349\"\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 draftOrderComplete($id: ID!) {\n draftOrderComplete(id: $id) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/DraftOrder/276395349\"\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 draftOrderComplete($id: ID!) {\n draftOrderComplete(id: $id) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/DraftOrder/276395349\",\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The draft order to complete.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/DraftOrder/276395349\"", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "draftordercomplete", "title": "Complete a draft order with payment pending", "description": "Completes a draft order with paymentPending set to true, which creates an order with a pending sale.", "query_string": "mutation draftOrderComplete($id: ID!, $paymentPending: Boolean) {\n draftOrderComplete(id: $id, paymentPending: $paymentPending) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n}", "variables": { "id": "gid://shopify/DraftOrder/276395349", "paymentPending": true }, "response": { "data": { "draftOrderComplete": { "draftOrder": { "id": "gid://shopify/DraftOrder/276395349", "order": { "id": "gid://shopify/Order/1073459967" } } } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/draft_orders/test/unit/graph_api/admin/mutations/draft_order_complete_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 draftOrderComplete($id: ID!, $paymentPending: Boolean) { draftOrderComplete(id: $id, paymentPending: $paymentPending) { draftOrder { id order { id } } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentPending\": true\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderComplete($id: ID!, $paymentPending: Boolean) {\n draftOrderComplete(id: $id, paymentPending: $paymentPending) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentPending\": true\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 draftOrderComplete($id: ID!, $paymentPending: Boolean) {\n draftOrderComplete(id: $id, paymentPending: $paymentPending) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentPending\": true\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 draftOrderComplete($id: ID!, $paymentPending: Boolean) {\n draftOrderComplete(id: $id, paymentPending: $paymentPending) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentPending\": true\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 draftOrderComplete($id: ID!, $paymentPending: Boolean) {\n draftOrderComplete(id: $id, paymentPending: $paymentPending) {\n draftOrder {\n id\n order {\n id\n }\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/DraftOrder/276395349\",\n \"paymentPending\" => true,\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The draft order to complete.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/DraftOrder/276395349\"", "typeKind": "MUTATION" }, { "arg": { "name": "paymentPending", "description": "Whether the payment is pending.", "type": { "kind": "SCALAR", "name": "Boolean", "list": false, "non_null": false }, "defaultValue": "false", "typeSignature": "Boolean", "isDeprecated": true, "deprecationReason": "Create a draft with payment terms rather than marking the draft as pending.", "kind": "ARGUMENT" }, "key": "paymentPending", "argValue": " true", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "draftordercomplete", "title": "Completing a draft order with an invalid payment gateway returns a user error", "query_string": "mutation draftOrderComplete($id: ID!, $paymentGatewayId: ID) {\n draftOrderComplete(id: $id, paymentGatewayId: $paymentGatewayId) {\n userErrors {\n message\n field\n }\n }\n}", "variables": { "id": "gid://shopify/DraftOrder/276395349", "paymentGatewayId": "gid://shopify/PaymentGateway/12121213" }, "response": { "data": { "draftOrderComplete": { "userErrors": [ { "message": "Invalid payment gateway", "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_complete_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 draftOrderComplete($id: ID!, $paymentGatewayId: ID) { draftOrderComplete(id: $id, paymentGatewayId: $paymentGatewayId) { userErrors { message field } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentGatewayId\": \"gid://shopify/PaymentGateway/12121213\"\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation draftOrderComplete($id: ID!, $paymentGatewayId: ID) {\n draftOrderComplete(id: $id, paymentGatewayId: $paymentGatewayId) {\n userErrors {\n message\n field\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentGatewayId\": \"gid://shopify/PaymentGateway/12121213\"\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 draftOrderComplete($id: ID!, $paymentGatewayId: ID) {\n draftOrderComplete(id: $id, paymentGatewayId: $paymentGatewayId) {\n userErrors {\n message\n field\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentGatewayId\": \"gid://shopify/PaymentGateway/12121213\"\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 draftOrderComplete($id: ID!, $paymentGatewayId: ID) {\n draftOrderComplete(id: $id, paymentGatewayId: $paymentGatewayId) {\n userErrors {\n message\n field\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/DraftOrder/276395349\",\n \"paymentGatewayId\": \"gid://shopify/PaymentGateway/12121213\"\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 draftOrderComplete($id: ID!, $paymentGatewayId: ID) {\n draftOrderComplete(id: $id, paymentGatewayId: $paymentGatewayId) {\n userErrors {\n message\n field\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/DraftOrder/276395349\",\n \"paymentGatewayId\" => \"gid://shopify/PaymentGateway/12121213\",\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The draft order to complete.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/DraftOrder/276395349\"", "typeKind": "MUTATION" }, { "arg": { "name": "paymentGatewayId", "description": "The gateway for the completed draft order.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": false }, "defaultValue": null, "typeSignature": "ID", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "paymentGatewayId", "argValue": " \"gid://shopify/PaymentGateway/12121213\"", "typeKind": "MUTATION" } ] } ]