draftOrderUpdate
Requires access scope. Also: The user must have access to manage draft orders.
Updates a draft order.
If a checkout has been started for a draft order, any update to the draft will unlink the checkout. Checkouts are created but not immediately completed when opening the merchant credit card modal in the admin, and when a buyer opens the invoice URL. This is usually fine, but there is an edge case where a checkout is in progress and the draft is updated before the checkout completes. This will not interfere with the checkout and order creation, but if the link from draft to checkout is broken the draft will remain open even after the order is created.
Arguments
- •ID!required
Specifies the draft order to update.
- Anchor to inputinput•Draft
Order requiredInput! The draft order properties to update.
Anchor to DraftOrderUpdatePayload returnsDraftOrderUpdatePayload returns
- Anchor to draftOrderdraft•
Order The updated draft order.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation updateDraftOrderMetafields($input: DraftOrderInput!, $ownerId: ID!) {6 draftOrderUpdate(input: $input, id: $ownerId) {7 draftOrder {8 id9 metafields(first: 3) {10 edges {11 node {12 id13 namespace14 key15 value16 }17 }18 }19 }20 userErrors {21 message22 field23 }24 }25 }`,26 {27 variables: {28 "input": {29 "metafields": [30 {31 "namespace": "my_field",32 "key": "delivery_instructions",33 "type": "single_line_text_field",34 "value": "leave on back porch"35 },36 {37 "id": "gid://shopify/Metafield/1069229059",38 "value": "123"39 }40 ]41 },42 "ownerId": "gid://shopify/DraftOrder/276395349"43 },44 },45);4647const data = await response.json();48
mutation updateDraftOrderMetafields($input: DraftOrderInput!, $ownerId: ID!) {
draftOrderUpdate(input: $input, id: $ownerId) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updateDraftOrderMetafields($input: DraftOrderInput!, $ownerId: ID!) { draftOrderUpdate(input: $input, id: $ownerId) { draftOrder { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
},
{
"id": "gid://shopify/Metafield/1069229059",
"value": "123"
}
]
},
"ownerId": "gid://shopify/DraftOrder/276395349"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation updateDraftOrderMetafields($input: DraftOrderInput!, $ownerId: ID!) {
draftOrderUpdate(input: $input, id: $ownerId) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
},
{
"id": "gid://shopify/Metafield/1069229059",
"value": "123"
}
]
},
"ownerId": "gid://shopify/DraftOrder/276395349"
},
},
);
const data = await response.json();
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation updateDraftOrderMetafields($input: DraftOrderInput!, $ownerId: ID!) {
draftOrderUpdate(input: $input, id: $ownerId) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [{"namespace"=>"my_field", "key"=>"delivery_instructions", "type"=>"single_line_text_field", "value"=>"leave on back porch"}, {"id"=>"gid://shopify/Metafield/1069229059", "value"=>"123"}]
},
"ownerId": "gid://shopify/DraftOrder/276395349"
}
response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation updateDraftOrderMetafields($input: DraftOrderInput!, $ownerId: ID!) {
draftOrderUpdate(input: $input, id: $ownerId) {
draftOrder {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_instructions",
"type": "single_line_text_field",
"value": "leave on back porch"
},
{
"id": "gid://shopify/Metafield/1069229059",
"value": "123"
}
]
},
"ownerId": "gid://shopify/DraftOrder/276395349"
},
},
});
Input variables
JSON1{2 "input": {3 "metafields": [4 {5 "namespace": "my_field",6 "key": "delivery_instructions",7 "type": "single_line_text_field",8 "value": "leave on back porch"9 },10 {11 "id": "gid://shopify/Metafield/1069229059",12 "value": "123"13 }14 ]15 },16 "ownerId": "gid://shopify/DraftOrder/276395349"17}
Response
JSON1{2 "draftOrderUpdate": {3 "draftOrder": {4 "id": "gid://shopify/DraftOrder/276395349",5 "metafields": {6 "edges": [7 {8 "node": {9 "id": "gid://shopify/Metafield/1069229059",10 "namespace": "my_fields",11 "key": "purchase_order",12 "value": "123"13 }14 },15 {16 "node": {17 "id": "gid://shopify/Metafield/1069229060",18 "namespace": "my_field",19 "key": "delivery_instructions",20 "value": "leave on back porch"21 }22 }23 ]24 }25 },26 "userErrors": []27 }28}