Skip to content

Instantly share code, notes, and snippets.

@DheerajP
Last active September 5, 2024 14:15
Show Gist options
  • Save DheerajP/99ac049fc025d990fafd006d2469baa1 to your computer and use it in GitHub Desktop.
Save DheerajP/99ac049fc025d990fafd006d2469baa1 to your computer and use it in GitHub Desktop.
Update Contentful entries with a tag
const contentful = require("contentful-management");
const client = contentful.createClient({
accessToken: "<Replace with your access token>",
});
client
.getSpace("<Replace with your spaceID>")
.then((space) => space.getEnvironment("<Replace with Env ID>"))
.then((environment) =>
environment.getEntries({ content_type: "<Replace with CT ID>" })
)
.then((entries) => {
// Process each entry
entries.items.forEach((entry) => {
const myTag = {
sys: {
type: "Link",
linkType: "Tag",
id: "<replace with tag ID>",
},
};
entry.metadata.tags.push(myTag);
entry.update();
//if you want to publish - uncomment this.
entry.publish();
});
})
.catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment