Hi, I tried to research before asking, and I understand a few things, but need help completing the puzzle. I have a nodejs web app that I want to programmatically create forum users from, suspend them, switch their groups, etc. I added my own API key (40 characters) to the api_key table. These are the API routes I could find/figure out:
To suspend user:
POST to https://forums.mydomain.com/api/users/2 was used to suspend user (but I need their ID#)
send data: {type: "users", id: "2", attributes: {suspendedUntil: "2038-01-01T00:00:00.000Z"}}}
to unsuspend set suspendedUntil: null
To switch membership group:
POST to https://forums.mydomain.com/api/users/2
data {...} contains id: "2", type: "users", attributes: {username: "TheirUserName", email: "Their@email.com"}, relationships: {groups: {data: [{type: "groups", id: "5"}]}}
To create user:
POST to https://forums.mydomain.com/register
{email: "Their@email.com", password: "thispassword", username: "TheirUserName"}
Is the create user post to /register the best option or is there actually another api route available for that? If I have registration closed, I am assuming I won't be able to use /register to create a user so I would need a different api route? Also, if I want to modify member groups or suspend a user, I need a way to get all their info like id, name, etc. I guess I could store that info in my app if another, better, create api route exists and will return that needed info to my app in the response. I really could not find any documentation for the REST API just for extensions/php. Please help me out with what I am missing here? 😅
edit: OH! I just found: /src/Api/routes.php maybe this will clue me in some more. Okay, found
create user at:
POST to https://forums.mydomain.com/api/users
but I can't figure out how to include my custom API key into the header properly. I tried calling it 'TOKEN' and 'authorization' and 'api_key' but not having any luck. Okay, now I found _docs/api.md and hopefully that was the last bit I need. Hopefully soon there can be updated docs for the endpoints for others looking for this.
Edit: I'm really stuck now. It's taking my API key, but it can not see the json data I am sending it at all, and just tells me that the data is required. I'm sending it as raw, application/json, using postman just to test it. What am I doing wrong?
Holy Moly! I finally got it! 😀 I had to change the json to be an object containing data which contains attributes, which contains the user information. Between hunting for the routes, hunting for how to do the token, hunting for the proper data format to send in the body, that took quite a while of my day. 🙁
One last issue I am facing: If I want to programatically set the new user to a group, I can't seem to do so. I tried doing a PATCH to /api/users/2 and pass it {"data": { "attributes": {"username":"UserName", "email":"user@mail.com", "password":"testpw"}, "relationships": { "groups": {"data": [{"type": "groups", "id": "5"}]} }}}
but all I get as a response is "Method_Not_Allowed", same with a POST to /api/users, same if I try including the group info with the user create request. I take it, it is not possible?