Unable to create user with C# administration object
Hi Rainbow Support,
I've been developing an app with rainbow sandbox and I've run into an issue when creating users in the C# sdk.
I attempt to login with an admin account which succeeds
I then try to create an Administration Object with the getAdminstration() function: https://hub.openrainbow.com/#/documentation/doc/sdk/csharp/api/Rainbow.Administration
Finally I try to run the CreateUser Function and I get an incorrect use message of unauthorised.
This is strange to me as using the exact same credentials for the Rainbow CLI and the web portal (web-sandbox.openrainbow.com), I'm quite easily able to create users.
Here are some code snippets
rainbowApp = new Rainbow.Application();
//appId and appSecret are provided by the sand box SDK integration
//hostname is sandbox.openrainbow.com
rainbowApp.Login(RainbowUsername, RainbowPassword, callback =>
result = true;
// A pb occurs
if (callback.Result.Type == Rainbow.SdkError.SdkErrorType.IncorrectUse)
// Bad parameter(s) used
msg = callback.Result.IncorrectUseError.ErrorMsg;
// Exception occurs
Exception e = callback.Result.ExceptionError;
var admin = _rainbowApp.GetAdministration();
admin.CreateUser(userEmailAddress, userPassword, firstName, lastName, null , null, true, createAdmin, callback =>
//Similar Error Checking to Above
In your example, you have created a user without specifying its companyId. (the argument after lastName)
It's better to specify it. Without it, it really depends of the right of the user you use.
If you still have a pb, please provide me the exact error you have.
Note: I suggest you to use something like that to log error:
I modified the code to now include a nickname and the company id as seen below:
admin.CreateUser(userEmailAddress, userPassword, firstName, lastName, firstName, company_id, true, createAdmin, callback
The error I received was:
ErrorCode: - ErrorMsg:[Unauthorized] - ErrorDetails:[Format is Authorization: Bearer [token]] - ErrorDetailsCode:
Never Mind I managed to fix it by placing the following code between the login and the admin call.
while (_rainbowApp.ConnectionState() != Rainbow.Model.ConnectionState.Connected || !_rainbowApp.IsInitialized())
if (_rainbowApp.ConnectionState() == Rainbow.Model.ConnectionState.Disconnected)
Take into account that all API using a callback are asynchronous. So you need to have an answer (i.e. checking result of "callback.Result.Success") before to continue.
Login process is even more complex because the callback of this API provide you the information of correct or incorrect login/pwd. If they are correct you need also to wait event "InitializationPerformed" because it's necessary to gather several information for server before to be fully operational.
Please sign in to leave a comment.