I’ve found a few examples in these forums of updating user info via the API but can’t get it to work. I’m a junior developer so maybe I’m missing something obvious.
First I tried getting this example to work: curl -X PUT -d 'name=new name’ -L 'https://mysite.com/users/user12345.json?api_key=mykey&api_username=username'
Thanks @JammyDodger . I did as you suggested and updated the name in the admin UI and then looked in the network tab. As you mentioned it does the update at a different url (/u instead of /users), but when I change the URL it’s still not working.
Under “Form Data”, I’m looking at the request and it is: name: "newname" just like I’m sending it.
As far as I can tell everything looks right and its still not updating. Stumped.
Ok… I spent a lot more time digging through the forums and found a similar issue from 7 years ago. Turns out if you update the Content-Type to “application/json; charset=utf-8” it works!
I have one last issue: how do I update the username via the API?
I’ve tried doing something like this but it doesnt work:
-d '{"name”: “new name", "username": "new username"}' \
Ok… I was finally able to figure this out. Will leave a little summary here in case someone in the future is looking for how to do this. The other answers I found on the forums were out of date.
To update the name via API: curl -X PUT -H "Content-Type: application/json; charset=utf-8" -H "Api-Key: mykey" -H "Api-Username: username" -d '{"name": “mynewname"}' -L 'https://mysite.com/u/user12345.json'
To update the username via API: curl -X PUT -H "Content-Type: application/json; charset=utf-8" -H "Api-Key: myapikey" -H "Api-Username: username" -d '{"new_username": "mynewusername"}' -L 'https://mysite.com/u/user12345/preferences/username.json'