Anchor to section titled 'undefined'

draftOrderUpdate
mutation

Requires write_draft_orders 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.


Anchor to id
id
required

Specifies the draft order to update.

The draft order properties to update.


Was this section helpful?

The updated draft order.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
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-01/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/1069229013",
          "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/1069229013",
            "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/1069229013", "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/1069229013",
            "value": "123"
          }
        ]
      },
      "ownerId": "gid://shopify/DraftOrder/276395349"
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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/1069229013", "value"=>"123"}],
  ],
  "ownerId" => "gid://shopify/DraftOrder/276395349",
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "input": {
    "metafields": [
      {
        "namespace": "my_field",
        "key": "delivery_instructions",
        "type": "single_line_text_field",
        "value": "leave on back porch"
      },
      {
        "id": "gid://shopify/Metafield/1069229013",
        "value": "123"
      }
    ]
  },
  "ownerId": "gid://shopify/DraftOrder/276395349"
}
Hide code
Response
JSON
{
  "draftOrderUpdate": {
    "draftOrder": {
      "id": "gid://shopify/DraftOrder/276395349",
      "metafields": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/Metafield/1069229013",
              "namespace": "my_fields",
              "key": "purchase_order",
              "value": "123"
            }
          },
          {
            "node": {
              "id": "gid://shopify/Metafield/1069229014",
              "namespace": "my_field",
              "key": "delivery_instructions",
              "value": "leave on back porch"
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}