Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

Reply
New Contributor
shyamalvaidya
Posts: 7
Registered: ‎04-26-2013
My Device: z10
My Carrier: ATT

getting UNKNOWN Error while trying create new blackberry enabled user.

Hello,

 

I have almost everything from the API documentation C#.

 

Got  AccountAttributes and trying to createUser by Email, Display Name or UserID.

Nothing was working for me.

 

 

public

staticboolCreateUser()

{

/////////////////////////////////////////////////////////

 

conststring methodName1 = "GetServers()";

 

conststring bwsApiServerName = "bwsService.GetServers()";

logMessage(

"Entering {0}", methodName1);

 

bool returnValue1 = false;

 

GetServersRequest getServerRequest = newGetServersRequest();

 

GetServersResponse response1 = null;

getServerRequest.metadata = Metadata;

getServerRequest.hostName =

"apsed0877";

 

//List<Server> newServer = new List<Server>();//newServer.Add(newServer);//request1.newServer = newServer.ToArray();//newUser.server = null;

logRequest(bwsApiServerName);

try

{

logRequest(bwsApiServerName);

response1 = bwsService.getServers(getServerRequest);

logResponse(bwsApiServerName, response1.returnStatus.code, response1.metadata);

// string[] array1 = response1.

}

catch (WebExceptione)

{

HttpWebResponse webResponse = e.Response asHttpWebResponse;

 

// Handle authentication failure.if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)

{

logMessage(

"Failed to get servers");

logMessage(

"Exiting {0} with value \"{1}\"", methodName1, returnValue1);

 

returnreturnValue1;

}

// Log and re-throw exception.

logMessage(

"Exiting {0} with exception \"{1}\"", methodName1, e.Message);

 

throwe;

}

if (response1.returnStatus.code.Equals("SUCCESS"))

{

returnValue1 =

true;

}

else

{

logMessage(

"Error Message: \"{0}\"", response1.returnStatus.message);

}

logMessage(

"Exiting {0} with value \"{1}\"", methodName1, returnValue1);

 

// return returnValue1;

 

////////////////////////////////////////////////////////

 

conststring methodName = "CreateUser()";

 

conststring bwsApiName = "bwsService.createUser()";

 

// const string bwsApiServerName = "bwsService.GetServers()";

logMessage(

"Entering {0}", methodName);

 

bool returnValue = false;

 

// Create the request object.CreateUsersRequest createUsersRequest = newCreateUsersRequest();

createUsersRequest.metadata = Metadata;

NewUser newUser = newNewUser();

 

// To create an administrator user, create and set the "UserAttributes".AccountAttributes accountAttributes = newAccountAttributes();

 

// UserAttributes userAttributes = new UserAttributes();/*

* Check if value of the variable "CreateNewUserEmail" is enclosed in double-quotes,

* otherwise the string would infer a substring match search.

*/

if (!CreateNewUserEmail.StartsWith("\"") || !CreateNewUserEmail.EndsWith("\""))

{

logMessage(

"Warning: Email Address \"{0}\" is not enclosed in double-quotes",

CreateNewUserEmail);

}

 

//GetAuthenticatorsRequest request = new GetAuthenticatorsRequest();// request.metadata = Metadata;//if (userAttributes.authenticator.authenticatorType.PLUGIN) //{ userAttributes.domain = "MS"; }

accountAttributes.emailAddress = CreateNewUserEmail;

//

newUser.accountAttributes = accountAttributes;

newUser.server = response1.servers[0];

// newUser.server = GetServerInfo;// newUser.userAttributes = userAttributes;// Randomly select a BlackBerry Enterprise Server on which to create the user.List<NewUser> newUsers = newList<NewUser>();

newUsers.Add(newUser);

createUsersRequest.newUsers = newUsers.ToArray();

CreateUsersResponse response = null;

 

try

{

logRequest(bwsApiName);

response = bwsService.createUsers(createUsersRequest);

logResponse(bwsApiName, response.returnStatus.code, response.metadata);

}

catch (WebExceptione)

{

// Log and re-throw exception.

logMessage(

"Exiting {0} with exception \"{1}\"", methodName, e.Message);

 

throwe;

}

if (response.returnStatus.code.Equals("SUCCESS"))

{

if (response.individualResponses != null)

{

foreach (IndividualResponse individualResponse inresponse.individualResponses)

{

displayResult(

"User created with UID \"{0}\" using Email Address \"{1}\"",

individualResponse.uid, accountAttributes.emailAddress);

//individualResponse.uid, userAttributes.displayName);

}

returnValue =

true;

}

}

else

{

logMessage(

"Error Message: \"{0}\"", response.returnStatus.message);

 

if (response.individualResponses != null)

{

foreach (IndividualResponse individualResponse inresponse.individualResponses)

{

logMessage(

"Individual Response - Code: \"{0}\", Message: \"{1}\"",

individualResponse.returnStatus.code, individualResponse.returnStatus.message);

}

}

}

logMessage(

"Exiting {0} with value \"{1}\"", methodName, returnValue);

 

returnreturnValue;

}

 

 

Please suggest, How should I take care of.

Shy

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

Hi Shy, and welcome to the forums!

 

Which line of code is throwing the error? Also, could you paste your code in a code block so the formatting remains unchanged and easier to read (there is an "Insert Code" item in the toolbox)?

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
shyamalvaidya
Posts: 7
Registered: ‎04-26-2013
My Device: z10
My Carrier: ATT

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

hello gbeukeboom

 

thanks for responding quick.

 

Line is -

response = bwsService.createUsers(createUsersRequest);

 

at that point I get returnStatus as UNKNOWN - I am passing EmailAddess for account attribute in CreateUser.

 

 public static bool CreateUser()
        {






            /////////////////////////////////////////////////////////


            const string methodName1 = "GetServers()";
            const string bwsApiServerName = "bwsService.GetServers()";
            logMessage("Entering {0}", methodName1);
            bool returnValue1 = false;


            GetServersRequest getServerRequest = new GetServersRequest();
            GetServersResponse response1 = null;

            getServerRequest.metadata = Metadata;
            getServerRequest.hostName = "apsed0877";

            //List<Server> newServer = new List<Server>();
            //newServer.Add(newServer);
            //request1.newServer = newServer.ToArray();
            //newUser.server = null;
            logRequest(bwsApiServerName);



            try
            {
                logRequest(bwsApiServerName);
                response1 = bwsService.getServers(getServerRequest);
                logResponse(bwsApiServerName, response1.returnStatus.code, response1.metadata);
                // string[] array1 = response1.
            }
            catch (WebException e)
            {
                HttpWebResponse webResponse = e.Response as HttpWebResponse;
                // Handle authentication failure.
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                {
                    logMessage("Failed to get servers");
                    logMessage("Exiting {0} with value \"{1}\"", methodName1, returnValue1);
                    return returnValue1;
                }
                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName1, e.Message);
                throw e;

            }

            if (response1.returnStatus.code.Equals("SUCCESS"))
            {
                returnValue1 = true;

            }
            else
            {
                logMessage("Error Message: \"{0}\"", response1.returnStatus.message);
            }

            logMessage("Exiting {0} with value \"{1}\"", methodName1, returnValue1);
          //  return returnValue1;








            ////////////////////////////////////////////////////////







            const string methodName = "CreateUser()";
            const string bwsApiName = "bwsService.createUser()";
          // const string bwsApiServerName = "bwsService.GetServers()";
            logMessage("Entering {0}", methodName);
            bool returnValue = false;

            // Create the request object.
            CreateUsersRequest createUsersRequest = new CreateUsersRequest();
            createUsersRequest.metadata = Metadata;
            

            NewUser newUser = new NewUser();

            // To create an administrator user, create and set the "UserAttributes".
          AccountAttributes accountAttributes = new AccountAttributes();
           // UserAttributes userAttributes = new UserAttributes();

            /* 
             * Check if value of the variable "CreateNewUserEmail" is enclosed in double-quotes,
             * otherwise the string would infer a substring match search.
             */
            if (!CreateNewUserEmail.StartsWith("\"") || !CreateNewUserEmail.EndsWith("\""))
            {
                logMessage("Warning: Email Address \"{0}\" is not enclosed in double-quotes",
                    CreateNewUserEmail);
            }
            // Value of the variable "CreateNewUserEmail" is used to create a BlackBerry-enabled user.
            ///////logMessage("Creating a user with email address \"{0}\"", CreateNewUserEmail);
            //userAttributes.loginName = "svaidy8";
            //userAttributes.domain = "MS";
            //userAttributes.displayName = "Vaidya, Shyamal";



          //GetAuthenticatorsRequest request = new GetAuthenticatorsRequest();
          //  request.metadata = Metadata;
          
            


   

            //if (userAttributes.authenticator.authenticatorType.PLUGIN) 
            //{ userAttributes.domain = "MS"; }

            accountAttributes.emailAddress = CreateNewUserEmail;
            //accountAttributes.userDistinguishedName = "displayName=Vaidya, Shyamal";
           // accountAttributes.Any = "";
         // "\"shyamal_vaidya@uhc.com\"";
            //accountAttributes.externalUserUid = "MS\"svaidy8";

          newUser.accountAttributes = accountAttributes;
          newUser.server = response1.servers[0];
         // newUser.server = GetServerInfo;
            
           // newUser.userAttributes = userAttributes;
            // Randomly select a BlackBerry Enterprise Server on which to create the user.
          
            List<NewUser> newUsers = new List<NewUser>();
            newUsers.Add(newUser);
            createUsersRequest.newUsers = newUsers.ToArray();

            CreateUsersResponse response = null;

            try
            {
                logRequest(bwsApiName);
                response = bwsService.createUsers(createUsersRequest);
                logResponse(bwsApiName, response.returnStatus.code, response.metadata);
            }
            catch (WebException e)
            {
                // Log and re-throw exception.
                logMessage("Exiting {0} with exception \"{1}\"", methodName, e.Message);
                throw e;
            }

            if (response.returnStatus.code.Equals("SUCCESS"))
            {
                if (response.individualResponses != null)
                {
                    foreach (IndividualResponse individualResponse in response.individualResponses)
                    {
                        displayResult("User created with UID \"{0}\" using Email Address \"{1}\"",
                           individualResponse.uid, accountAttributes.emailAddress);
                           //individualResponse.uid, userAttributes.displayName);
                    }

                    returnValue = true;
                }
            }
            else
            {
                logMessage("Error Message: \"{0}\"", response.returnStatus.message);
                if (response.individualResponses != null)
                {
                    foreach (IndividualResponse individualResponse in response.individualResponses)
                    {
                        logMessage("Individual Response - Code: \"{0}\", Message: \"{1}\"",
                            individualResponse.returnStatus.code, individualResponse.returnStatus.message);
                    }
                }
            }

            logMessage("Exiting {0} with value \"{1}\"", methodName, returnValue);
            return returnValue;
        }

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

Here is the code that works for me:

 

        public static void CreateUsers(){
           CreateUsersRequest request = new CreateUsersRequest();
           request.metadata = Metadata;        

           AccountAttributes accountAttributes=new AccountAttributes();
           accountAttributes.emailAddress = "user01@example.com";

           NewUser newUser=new NewUser();
           newUser.accountAttributes = accountAttributes;        
           newUser.server = null;

           request.newUsers = new NewUser[] { newUser };
           CreateUsersResponse response = bwsService.createUsers(request);
                        
           if (response.returnStatus.code.CompareTo("SUCCESS")!=0) {
               Console.Out.WriteLine("Error occurred: " + response.returnStatus.code);
           }else{
               foreach (IndividualResponse itr in response.individualResponses) {
                   Console.Out.WriteLine("User created. Uid is: " + itr.uid);
               }
           }
        }

 

It's a few lines shorter than what you are using and may help pinpoint the issue. If you continue to receive errors then please let me know what other calls are working as expected and the version of BES you are using.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
New Contributor
shyamalvaidya
Posts: 7
Registered: ‎04-26-2013
My Device: z10
My Carrier: ATT

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

So I tried your code,

 

Its still giving me UNKNOWN status, and Internal Error Occured as a returnStatus from create user account.

Now we are using 6.2 version.

 

and Its an AD connection we are try to get, So we have all these users in AD and we want to create users by their Email Address.

 

I think I am missing some tags.

 

I am using GetServers(), GEtSystemInfo(), GEtEncodedUserName() these are the main calls Im making.

 

Thanks,

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

Likely a silly question, but did you change the email address in my code to a legit one in your environment?

 

Are you able to create this same user through the BAS console using the same credentials being used for your BWS app?

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
cmolkentine
Posts: 14
Registered: ‎04-26-2013
My Device: Blackberry z10
My Carrier: AT&T

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

Hi Garett,

 

Yes he did change the email address in the code to a legit one in the environment.   The account can be created via the console using the supplied credentials.   We just want it to create a blackberry enabled account with no need to login to the console.

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

Do other calls complete as expected? For example can you call getUsers and display all users on the BAS?

 

The question above was a troubleshooting step only, I understand the desire is to get this working programmatically :smileywink:

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
cmolkentine
Posts: 14
Registered: ‎04-26-2013
My Device: Blackberry z10
My Carrier: AT&T

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

Yes GetUsers, GetServers, and GetSystemInfo are all working. Create user fails with .bwsService.createuser() returned "UNKNOWN" and further down it says Error Message: "Internal Error. Runtime Exception occured."

Please use plain text.
Contributor
cmolkentine
Posts: 14
Registered: ‎04-26-2013
My Device: Blackberry z10
My Carrier: AT&T

Re: getting UNKNOWN Error while trying create new blackberry enabled user.

[ Edited ]

The unknown error seems to be gone now, but getting Code: USER_CREATION_FAILED", Message: "Failed to create user: Mail account not found."   Does not look like it is getting the information from active directory to create the user.

This is if I change the line to look for userDistinguishedName.   Forgot to mention we have BES 10 running Blackberry Device Service 6.2

Please use plain text.