Hi Kasper,
I'm testing out vanilla forums/the api to see if it will fit my use case. In the course of that, I tried updating a user through the api, and I can't get it to work; I receive a 400 response that says "You must select at least one role." I'm definitely including an array of role IDs.
I'm running vanilla locally (using MAMP). I can successfully update a user through the api using Postman (I also tried RESTClient just for kicks, and it worked as well), but I haven't been successful using cURL in either a PHP script or from the command-line (Mac OS 10.7, curl version 7.21.4).
Here's what I did from the command-line:
curl -v -X PUT -H "Content-Type: application/json" '{"Name":"test","Email":"[email protected]","Password":"password","RoleID":[8]}' "http://localhost/api/users/3?username=[username]×tamp=[timestamp]&token=[token]"
And this is the response I get:
{
"AllowEditing": true,
"User": {
"UserID": "3",
"Name": "test",
"Photo": null,
"Title": null,
"Location": null,
"About": null,
"Email": "[email protected]",
"ShowEmail": "0",
"Gender": "u",
"CountVisits": "0",
"CountInvitations": "0",
"CountNotifications": null,
"InviteUserID": null,
"DiscoveryText": null,
"Preferences": null,
"DateSetInvitations": null,
"DateOfBirth": null,
"DateFirstVisit": "2015-03-11 00:12:27",
"DateLastActive": "2015-03-11 00:12:27",
"LastIPAddress": "127.0.0.1",
"AllIPAddresses": null,
"DateInserted": "2015-03-11 00:12:27",
"InsertIPAddress": "127.0.0.1",
"DateUpdated": "2015-03-13 06:00:48",
"UpdateIPAddress": "127.0.0.1",
"HourOffset": "0",
"Score": null,
"Admin": "0",
"Confirmed": "1",
"Verified": "0",
"Banned": "0",
"Deleted": "0",
"Points": "0",
"CountUnreadConversations": null,
"CountDiscussions": null,
"CountUnreadDiscussions": null,
"CountComments": null,
"CountDrafts": null,
"CountBookmarks": null,
"_CssClass": "",
"ConfirmEmail": 1
},
"Roles": {
"2": "Guest",
"3": "Unconfirmed",
"4": "Applicant",
"8": "Member",
"32": "Moderator",
"16": "Administrator"
},
"UserRoles": [
],
"Code": 400,
"Exception": "You must select at least one role."
}
I get the same response when I use cURL in PHP. I haven't been able to find any differences between the Postman client and what I'm doing in cURL. I'm definitely supplying user roles; I have a suspicion that the error message is a red herring.
I've tried recreating every single insignificant header, triple-checking the json...I can' t understand why my cURL request isn't working. Have you experienced this? Can you successfully update a user via the api with cURL, either from the command-line or PHP?