Requires write_orders access scope or write_marketplace_orders access scope. Also: The app must have the write_pos_staff_member_event_attribution_overrides scope to assign events to another staff member.

Updates the fields of an order.


The input for the mutation.


Was this section helpful?

The updated order.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation updateOrderMetafields($input: OrderInput!) {
  orderUpdate(input: $input) {
    order {
      id
      metafields(first: 3) {
        edges {
          node {
            id
            namespace
            key
            value
          }
        }
      }
    }
    userErrors {
      message
      field
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updateOrderMetafields($input: OrderInput!) { orderUpdate(input: $input) { order { 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/1069229021",
          "value": "123"
        }
      ],
      "id": "gid://shopify/Order/148977776"
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation updateOrderMetafields($input: OrderInput!) {
    orderUpdate(input: $input) {
      order {
        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/1069229021",
            "value": "123"
          }
        ],
        "id": "gid://shopify/Order/148977776"
      }
    },
  },
);

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 updateOrderMetafields($input: OrderInput!) {
    orderUpdate(input: $input) {
      order {
        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/1069229021", "value"=>"123"}],
    "id": "gid://shopify/Order/148977776"
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation updateOrderMetafields($input: OrderInput!) {
      orderUpdate(input: $input) {
        order {
          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/1069229021",
            "value": "123"
          }
        ],
        "id": "gid://shopify/Order/148977776"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation updateOrderMetafields($input: OrderInput!) {
    orderUpdate(input: $input) {
      order {
        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/1069229021", "value"=>"123"}],
    "id" => "gid://shopify/Order/148977776",
  ],
];

$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/1069229021",
        "value": "123"
      }
    ],
    "id": "gid://shopify/Order/148977776"
  }
}
Hide code
Response
JSON
{
  "orderUpdate": {
    "order": {
      "id": "gid://shopify/Order/148977776",
      "metafields": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/Metafield/1069229021",
              "namespace": "my_fields",
              "key": "purchase_order",
              "value": "123"
            }
          },
          {
            "node": {
              "id": "gid://shopify/Metafield/1069229022",
              "namespace": "my_field",
              "key": "delivery_instructions",
              "value": "leave on back porch"
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}