Last active
September 5, 2024 14:15
-
-
Save DheerajP/99ac049fc025d990fafd006d2469baa1 to your computer and use it in GitHub Desktop.
Update Contentful entries with a tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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