How do I add tags via the post api endpoint

I need to add a tags in my post api. How i do this?

  • I have already tried with tags array parameter in my api. But the post is created without any tag.
  • I also add minimum tags check in admin settings. Then it gives me an error. But no success.
    Any one know how to add tags in Post Api?
1 Like

I am having the same issue,

My php CURL call looks like this,

$body = '{
            "async": false,
            "title": "'.$word.'",
            "raw": "'.$definition.'",
            "category":'.$categoryId.',
            "topic_id": '.$topicsId.',
            "tags[]": "test-tag"
        }';

it is creating the topic via API but never creates the tags. what am i doing wrong?

When i made a new topic from my browser with tags, the form data looks like this,

and this creates the topic with the new tag.

But when i pass the tags in same format in the API call, it doesn’t seem to work. it only creates the topic but never creates any tag, even if old tag exists? Any ideas what am i doing wrong?
@tshenry @blake

You have the syntax right. Maybe php is eating your []? The actual curl command (no PHP) is working:

curl -i -sS -X POST "http://localhost:3000/posts.json"  \
-H "Content-Type: multipart/form-data;"  \
-H "Api-Key: ba8f7..."  \
-H "Api-Username: blake.erickson"  \
-F "title=2e45e2e8a239dk29d 1f35c2db23232323444a61 1e7e8a39797234"  \
-F "raw=f9ef6749c8736db0996bad662187bee6 8a5753d79c027e5a3a576b171c5bc085 a546f59b75bca6f54edd2af2ef069cf8" \
-F "tags[]=asdf" \
-F "tags[]=fdsa" \
-F "tags[]=foo"

image

EDIT:

Wait. Why are you including a topic id? You should only be able to add tags when creating a topic, not when creating a post (a reply to a topic).

2 Likes

@Faizan_Zahid I already figured it out. Try this syntax for tags

"tags" : ["test-tag"]

It worked for me

4 Likes

@blake There is no effect for this topic id