Create/update metafields on the Shop object

Solved

Create/update metafields on the Shop object

Richard687
Shopify Partner
19 1 15

I'm trying (and failing) to use the GraphQL API to add/update a private metafield on the Shop object using the privateMetafieldUpsert mutation.

I can get this to work fine on a Product object, but when it is given the ID of a Shop object it fails with the error "invalid id".

For example...

Mutation:

mutation ($input: PrivateMetafieldInput!) {
  privateMetafieldUpsert(input: $input) {
    privateMetafield {
      namespace
      key
      value
    }
    userErrors {
      field
      message
    }
  }
}

 

Variables: (shop ID has been changed)

{
  "input": {
    "owner": "gid://shopify/Shop/99999999",
    "namespace": "abc",
    "key": "xyz",
    "valueInput": {
      "value": "{}",
      "valueType": "JSON_STRING"
    }
  }
}

 

Result:

{
  "data": {
    "privateMetafieldUpsert": null
  },
  "errors": [
    {
      "message": "invalid id",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "privateMetafieldUpsert"
      ]
    }
  ],
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 1,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 999,
        "restoreRate": 50
      }
    }
  }
}

 

Does anyone know why this is failing?

Accepted Solution (1)

mkcny
Shopify Staff
1 1 2

This is an accepted solution.

Hi, Richard687.

This is not the most obvious thing, but you can create a private metafield on a shop simply by omitting the owner. It will default to the current shop as the owner.

Hope that helps.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 2 (2)

mkcny
Shopify Staff
1 1 2

This is an accepted solution.

Hi, Richard687.

This is not the most obvious thing, but you can create a private metafield on a shop simply by omitting the owner. It will default to the current shop as the owner.

Hope that helps.

To learn more visit the Shopify Help Center or the Community Blog.

Richard687
Shopify Partner
19 1 15

Many thanks. That worked nicely.