Yeah, so your first attempt should work, and I can verify with the following curl command:
curl -X PUT http://www.beeminder.com/api/v1/users/USERNAME/goals/GOALNAME.json?auth_token=AUTHTOKEN&tags[]=one&tags[]=two&tags[]=three
checking the logs for the 3rd, I see a bunch of fiddling, trying to get it right, and I don’t see any instances that manage to hit on quite the right syntax with tag[]=thing&tag[]=otherthing
(e.g. there’s tags[]=nutrition,food
, and there’s tags[0]=food&tags[1]=nutrition
, and tags[][0]=nutrition&tags[][1]=food
, and tags[]=food&tags=nutrition
etc…)
The second way of doing it should also work, with the tags sent as JSON in the body of the request, and in this instance, I think it’s sort of a combo of some buggy behavior on our end + your tool maybe not doing quite what you think it is doing.
Allow me to attempt to explain myself with curl. Let’s compare the results of the following three commands:
command 1
curl -X PUT http://localhost:3000/api/v1/users/b/goals/fug.json -d "{\"auth_token\":\"THjZxsi1NBmsmA294V_G\",\"tags\":[\"wasp\",\"bee\",\"boson\"]}"
result: 401 unauthorized “Token missing or incorrect token” – erm, wtf?
command 2
curl -X PUT http://localhost:3000/api/v1/users/b/goals/fug.json?auth_token=THjZxsi1NBmsmA294V_G\ -d "{\"tags\":[\"wasp\",\"bee\",\"boson\"]}"
result: 200; no change – in context alongside command 1 result, beeminder is not parsing the json out of the body…
command 3
curl -X PUT http://localhost:3000/api/v1/users/b/goals/fug.json -d "{\"auth_token\":\"THjZxsi1NBmsmA294V_G\",\"tags\":[\"wasp\",\"bee\",\"boson\"]}" -H 'Content-Type: application/json'
result: 200; goal tags are updated
So, when I use my usual go-to ruby http library to test out api commands, it is making assumptions and filling in blanks for me, like setting content-type etc…
Anyway, I’d say Beeminder is not being consistent about how it’s handling content types there, and that bit is rather confusing. I’ll file a bug noting the behavior.
You should be able to set your tags by using the URL params as I showed above, or if you prefer sending the data in the body of the request, just be sure to set the content-type as well.