That’s exactly what I do on my board game community: whenever a board game is added to (or renamed on) my database, a tag and two custom topics are created/updated.
IIRC when I worked on this, there’s not a specific endpoint for creating a single tag (you can add a new one when creating a topic though), but I was able to use the batch tags upload to do this.
Something like this:
const formData = new FormData();
formData.append("file", Buffer.from("the-tag-name,an-optional-tag-group"), {
contentType: "text/csv",
filename: "tags.csv",
});
const { data } = await axios.post(`${process.env.DISCOURSE_URL}/tags/upload.json`, formData, {
headers: {
...formData.getHeaders(),
"Api-Key": process.env.API_KEY,
},
});