How to change tags of a story

For this you will need the Graphql id of the story (see How to get a Story).

And you will need to find the Global IDS of tags you want to add.

First let's search for "Global Tags" (not limited to a space) with the name

graphql
query SearchHashtags {
me {
searchGlobalTags(text: "a tag") {
tag {
id
name
}
}
searchHashtags(text: "hashtag") {
hashtag {
id
name
}
}
# OR Search tags of a given Facet
node(id: "RmFjZXQ6ImNvZ2l0b192ZWlsbGUi") {
... on Facet {
id
searchTags(text: "my query") {
tag {
id
name
}
}
}
}
}
}

Expected result:

response
{
"data": {
"me": {
"searchGlobalTags": [
{
"tag": {
"id": "VGFnOjEwOQ==",
"name": "a nice tag"
}
},
{
"tag": {
"id": "VGFnOjQwMw==",
"name": "another test tag"
}
},
{
"tag": {
"id": "VGFnOjI2Nw==",
"name": "tag in two"
}
}
],
"searchHashtags": [
{
"hashtag": {
"id": "SGFzaHRhZzozMDU=",
"name": "my cool hashtag"
}
},
{
"hashtag": {
"id": "SGFzaHRhZzo0MTI=",
"name": "Nouveau hashtag"
}
}
]
},
"node": {
"id": "RmFjZXQ6InRow6htZXMi",
"searchTags": [
{
"tag": {
"id": "VGFnOjEzOA==",
"name": "api versioning"
}
},
{
"tag": {
"id": "VGFnOjE0OQ==",
"name": "design"
}
}
]
}
}
}

Then Keep on the side the "id" of the tags you want to use.

If you don't find the tag you need, you can create a new tag in the facet:

graphql
mutation CreateANewTag {
tagCreate(input: {
facetId: "eWVhaCByaWdodCBpdCdzIGI2NA==",
names: {en: "Name of the tag"}
}) {
tag {
id
}
}
}

This example demonstrates how to add/remove Tags and Hashtags on a given content.

graphql
mutation storyTagExample($input: StoryTagInput!) {
storyTag(input: $input) {
story {
tags {
id
name
}
hashtags {
id
name
}
}
}
}
variables
{
"input": {
"id": "STORY_ID",
"addedTags": ["TAG_ID_1", "TAG_ID_2"],
"removedTags": ["TAG_ID_3"],
"addedHashtags": ["HASHTAG_ID_1"],
"removedHashtags": []
}
}

Expected result:

response
{
"data": {
"storyTag": {
"story": {
"tags": [
{ "id": "TAG_ID_1", "name": "Tag 1" },
{ "id": "TAG_ID_1", "name": "Tag 2" }
],
"hashtags": [{ "id": "HASHTAG_ID_1", "name": "Hashtag 1" }]
}
}
}
}

Was this page helpful?