0

Remove Tags

by
Published today

Remove tags from any taggable resource (product, order, customer, draft order, article) by its GID, e.g. gid://shopify/Order/123. Other tags are kept.

Script shopify Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
/**
4
 * Remove Tags
5
 * Remove tags from any taggable resource (product, order, customer, draft order, article) by its GID, e.g. gid://shopify/Order/123. Other tags are kept.
6
 */
7
export async function main(
8
  auth: RT.Shopify,
9
  resource_id: string,
10
  tags: string[]
11
) {
12
  const response = await fetch(
13
    `https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
14
    {
15
      method: "POST",
16
      headers: {
17
        "X-Shopify-Access-Token": auth.token,
18
        "Content-Type": "application/json",
19
        Accept: "application/json",
20
      },
21
      body: JSON.stringify({
22
        query: `mutation ($id: ID!, $tags: [String!]!) { tagsRemove(id: $id, tags: $tags) { node { id } userErrors { field message } } }`,
23
        variables: { id: resource_id, tags },
24
      }),
25
    }
26
  )
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  const { data, errors } = await response.json()
33
  if (errors) {
34
    throw new Error(JSON.stringify(errors))
35
  }
36
  if (data.tagsRemove.userErrors.length) {
37
    throw new Error(JSON.stringify(data.tagsRemove.userErrors))
38
  }
39

40
  return data.tagsRemove
41
}
42