Cannot add tags via the API

I’m trying to add tags via the API, but I’m doing something wrong.

Here’s a good request made from the website:

PUT https://example.com/t/ueber-die-kategorie-organisation/74 HTTP/1.1
Host: example.com
Connection: keep-alive
Content-Length: 53
Accept: */*
Origin: https://example.com
X-CSRF-Token: ■■■■■■■■■■■■■■■■■■■■■■
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
DNT: 1
Referer: https://example.com/t/ueber-die-kategorie-organisation/74
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,de;q=0.6
Cookie: ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

tags%5B%5D=archiv-organisation&tags%5B%5D=archiv-2015

Here’s what I am trying to do:

PUT https://example.com/t/74?api_key=■■■■■■■■■■■■■■■■■■■■&api_username=system HTTP/1.1
host: example.com
content-type: application/x-www-form-urlencoded
content-length: 22
Connection: close

tags%5B%5D=archiv-2015

The server responds with 403 Forbidden.

Does anyone see what I’m doing wrong?

Aha, I found it. As it turns out, the slug is required and must be correct for the API call to work.
That’s slightly annoying, but a solvable problem :slight_smile:

5 Likes

I am trying to update tags, buteven using the slug does not procude any change
URL: http://forumURL/t/topic_slug/topic_id?api_key=api_key&api_username=user_name
PUT DATA:
{"title": "Some title", "tags[]":"tag_id", "category_id": "category_id"}

It looks like you are JSON-Encoding the body, which won’t work. Your body should look like this:

tags%5B%5D=archiv-2015
4 Likes

Thank you, I realize now that I was trying to set the tags using a header
Content-type: application/json when it should be Content-Type: application/x-www-form-urlencoded

5 Likes

Hello, i have mistake when update tag for topics with keyword search.

Topic.find_by(name: ‘quận 1 Dt:’).update_all( tag: quận-1)

My console wrong? thank!

This topic was automatically closed after 2948 days. New replies are no longer allowed.