Admin REST API Create User 406 ERROR Not Acceptable
RéponduHi,
Sorry I initially posted this in the Help Assistance & Support community, but meant to post it here.
I am trying to create a user with the Admin REST Api, but getting "406 ERROR Not Acceptable"
I have tested GET and DELETE and I have no problem here.
What am I missing?
Here is my code:
var createUser = function createUser(companyId, token) {
varrequest= {
"companyId": companyId,
"loginEmail": "rbwtest1@amillan.co.uk",
"password": "Rbwtest1!",
"firstName": "John",
"lastName": "Doe",
"nickName": "",
"title": "Mr",
"jobTitle": "Bot",
"emails": [
{
"email": "rbwtest1@amillan.co.uk",
"type": "work"
}
],
"phoneNumbers": [
{
"number": "01234567891",
"country": "GBR",
"type": "Work",
"deviceType": "landline"
}
],
"country": "GBR",
"language": "en",
"timezone": "Europe/London",
"accountType": "free",
"roles": "user",
"adminType": "company_admin",
"isActive": "true",
"isInitialized": "false",
"visibility": "private",
"timeToLive": 0
}
console.log("request: "+JSON.stringify(request));
console.log("[DEMO] :: Try to create user using the token received", companyId);
returnnewPromise(function(resolve, reject) {
varsearchURL="/api/rainbow/admin/v1.0/users"
$.ajax({
url: protocol + host + ":" + port + searchURL,
method: "POST",
headers: {
"Authorization": "Bearer "+token,
"Accept": "application/json"
},
data:JSON.stringify(request)
}).done(function(data, textStatus, jqXHR) {
console.log("[DEMO] :: User creation success", data);
resolve(data);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log("[DEMO] :: User creation failed", errorThrown);
reject(errorThrown);
});
});
};
createUser(data.companyId, getToken("token")).then(function(data) {
console.log("User created", data);
}).catch(function(err) {
console.log("ERROR", err);
});
Regards,
Esben
-
Good morning Pascal,
I got it to work using the chrome extension: Restlet Client - REST API Testing.by removing parameter roles.
Here are the error returned by the tester:
{"errorCode": 400,"errorMsg": "Bad Request","errorDetails":[{"param": "roles","msg": "Invalid field roles. Expected an array containing string(s) from the following values list: [ 'superadmin',\n 'support',\n 'bp_admin',\n 'bp_finance',\n 'admin',\n 'company_support',\n 'admin_buyer',\n 'user',\n 'analytics',\n 'bot',\n 'pcg',\n 'guest',\n 'app_superadmin',\n 'app_admin',\n 'media_pillar',\n 'private_channels_admin',\n 'public_channels_admin' ]","value": "user"}],"errorDetailsCode": 400000}I also had to change the header from "Accept": "application/json" to "Content-Type": "application/json"I tested true/false too and they can be with or without "" both works.
One more thing the home page of the sandbox displays the wrong number of members:
https://web-sandbox.openrainbow.com/app/1.42.6/index.html#/main/home (shows 4 members even though I only go 2)
Regards,
Esben
-
Hi,
Some questions:
1- Without the "" around booleans, you got a 400 or still a 406 ?
2- I think I found the problem: doc generation with swagger.
"roles" waits for an array of stringPlease try with
"roles": ["user"],
3- About "home page of the sandbox displays the wrong number of members": I didn't get your problem
Thanks,
Pascal -
Here is an example of what is awaited:
{ "loginEmail": "user1@company.com", "password": "Password123!", "firstName": "Firstname", "lastName": "Lastname", "nickName": "Nickname", "title": "Mr.", "jobTitle": "Software developer", "emails": [ { "email": "user1@company.com", "type": "work" }, { "email": "user1@home.com", "type": "home" } ], "phoneNumbers": [ { "number": "0390909090", "type": "home", "deviceType": "landline", "country": "FRA" }, { "number": "0690909090", "type": "home", "deviceType": "mobile", "country": "FRA" } ], "country": "FRA", "language": "fr-FR", "timezone": "Europe/Paris", "accountType": "free", "roles": [ "user", "admin" ], "adminType": "company_admin", "companyId": "569ce8c8f9336c471b98eda1", "isActive": true, "isInitialized": true, "visibility": "public" }
Vous devez vous connecter pour laisser un commentaire.
Commentaires
7 commentaires