Create a new metafield and update another on an existing location
Description
Create a new metafield `my_field.delivery_type` and update an
existing metafield `global.store_hours` on a specific
location.
Alternatively, refer to the
[metafieldsSet](https://shopify.dev/api/admin-graphql/latest/mutations/metafieldsset) mutation
to create and/or update metafields on location resources.
Query
mutation updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) {
locationEdit(input: $input, id: $ownerId) {
location {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
Variables
{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) { locationEdit(input: $input, id: $ownerId) { location { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) {
locationEdit(input: $input, id: $ownerId) {
location {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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 updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) {
locationEdit(input: $input, id: $ownerId) {
location {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) {
locationEdit(input: $input, id: $ownerId) {
location {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) {
locationEdit(input: $input, id: $ownerId) {
location {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}' \
--variables \
'{
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-04/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation updateLocationMetafields($input: LocationEditInput!, $ownerId: ID!) {
locationEdit(input: $input, id: $ownerId) {
location {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
`,
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "delivery_type",
"type": "single_line_text_field",
"value": "local"
},
{
"id": "gid://shopify/Metafield/1069229306",
"value": "Open from 7am to 10pm"
}
]
},
"ownerId": "gid://shopify/Location/346779380"
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"locationEdit": {
"location": {
"id": "gid://shopify/Location/346779380",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069229306",
"namespace": "global",
"key": "store_hours",
"value": "Open from 7am to 10pm"
}
},
{
"node": {
"id": "gid://shopify/Metafield/1069229307",
"namespace": "my_field",
"key": "delivery_type",
"value": "local"
}
}
]
}
},
"userErrors": []
}
}
Edit a location and return the location ID
Description
Edit a location's name, address and fulfillsOnlineOrders status
Query
mutation locationEdit {
locationEdit(id: "gid://shopify/Location/346779380", input: {name: "Shipping Warehouse", address: {address1: "290 Bremner Blvd", city: "Toronto", zip: "M5V 3L9", provinceCode: "ON", countryCode: CA}, fulfillsOnlineOrders: false}) {
location {
id
name
address {
address1
provinceCode
countryCode
zip
}
fulfillsOnlineOrders
}
}
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation locationEdit { locationEdit(id: \"gid://shopify/Location/346779380\", input: {name: \"Shipping Warehouse\", address: {address1: \"290 Bremner Blvd\", city: \"Toronto\", zip: \"M5V 3L9\", provinceCode: \"ON\", countryCode: CA}, fulfillsOnlineOrders: false}) { location { id name address { address1 provinceCode countryCode zip } fulfillsOnlineOrders } } }"
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation locationEdit {
locationEdit(id: "gid://shopify/Location/346779380", input: {name: "Shipping Warehouse", address: {address1: "290 Bremner Blvd", city: "Toronto", zip: "M5V 3L9", provinceCode: "ON", countryCode: CA}, fulfillsOnlineOrders: false}) {
location {
id
name
address {
address1
provinceCode
countryCode
zip
}
fulfillsOnlineOrders
}
}
}`,
);
const json = await response.json();
return json.data;
}
Ruby
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 locationEdit {
locationEdit(id: "gid://shopify/Location/346779380", input: {name: "Shipping Warehouse", address: {address1: "290 Bremner Blvd", city: "Toronto", zip: "M5V 3L9", provinceCode: "ON", countryCode: CA}, fulfillsOnlineOrders: false}) {
location {
id
name
address {
address1
provinceCode
countryCode
zip
}
fulfillsOnlineOrders
}
}
}
QUERY
response = client.query(query: query)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: `mutation locationEdit {
locationEdit(id: "gid://shopify/Location/346779380", input: {name: "Shipping Warehouse", address: {address1: "290 Bremner Blvd", city: "Toronto", zip: "M5V 3L9", provinceCode: "ON", countryCode: CA}, fulfillsOnlineOrders: false}) {
location {
id
name
address {
address1
provinceCode
countryCode
zip
}
fulfillsOnlineOrders
}
}
}`,
});
Shopify CLI
shopify app execute \
--query \
'mutation locationEdit {
locationEdit(id: "gid://shopify/Location/346779380", input: {name: "Shipping Warehouse", address: {address1: "290 Bremner Blvd", city: "Toronto", zip: "M5V 3L9", provinceCode: "ON", countryCode: CA}, fulfillsOnlineOrders: false}) {
location {
id
name
address {
address1
provinceCode
countryCode
zip
}
fulfillsOnlineOrders
}
}
}'
Direct API Access
const response = await fetch('shopify:admin/api/2026-04/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation locationEdit {
locationEdit(id: "gid://shopify/Location/346779380", input: {name: "Shipping Warehouse", address: {address1: "290 Bremner Blvd", city: "Toronto", zip: "M5V 3L9", provinceCode: "ON", countryCode: CA}, fulfillsOnlineOrders: false}) {
location {
id
name
address {
address1
provinceCode
countryCode
zip
}
fulfillsOnlineOrders
}
}
}
`,
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"locationEdit": {
"location": {
"id": "gid://shopify/Location/346779380",
"name": "Shipping Warehouse",
"address": {
"address1": "290 Bremner Blvd",
"provinceCode": "ON",
"countryCode": "CA",
"zip": "M5V 3L9"
},
"fulfillsOnlineOrders": false
}
}
}