Error code: 400 back when create user on the Organization

I write a simple php code that use the createUser function to create a new user on the body. The following error appears:

"POST ". https://xx.XX.XX.XX/API/v1.0/Admin/org/1421086956/users failed, return code: error 400,:, request data: User_Full_Name " [email protected] true Pa55w0rd '

What does this error mean?

Here is my code:

 
/**
 * Function to create a VMware_VCloud_API_UserType data object.
 */
function createUserObj($userName, $password, $role=null, $isEnabled=null, $fullName=null, $emailAddress=null, $description=null) {
    $obj = new VMware_VCloud_API_UserType();
    $obj->set_name($userName);
    $obj->setFullName($fullName);
    $obj->setDescription($description);
    $obj->setPassword($password);
    $obj->setRole($role);
    $obj->setIsEnabled($isEnabled);
    $obj->setEmailAddress($emailAddress);

    return $obj;
}
 
/**
 * Create a new user on an existing organization.
 */
try {
    // create a service object
    $service = VMware_VCloud_SDK_Service::getService();
    // login to the service portal,
    $service->login($server, $auth, $httpConfig);
    // create an SDK Admin object
    $sdkAdmin = $service->createSDKAdminObj();
 
    // get references to administrative organization entities
    $adminOrgRefs = $sdkAdmin->getAdminOrgRefs('testOrg1'); // testOrg1 Organization are already created.
    // create SDK AdminOrg object
    $sdkAdminOrg = $service->createSDKObj($adminOrgRefs[0]);
    // get references to roles
    $adminRoleRefs = $sdkAdmin->getRoleRefs('Organization Administrator');
 
    // create a VMware_VCloud_API_UserType data object
    $userObj = createUserObj('API_Sample_user', 'Pa55w0rd', $adminRoleRefs[0], true, 'User_Full_Name', '[email protected]');
    // invoke createUser function on an SDK AdminOrg object
    $user = $sdkAdminOrg->createUser($userObj);
 
    // Print user list
    $userList = $sdkAdminOrg->getUserRefs();
    echo "<br> User List <br>";
    foreach ($userList as $user) {
        echo "{$user->get_name()} <br>";
    }
} catch (Exception $e) {
    echo $e->getMessage() . "\n";
}


Error code 400 is the standard HTTP status code, indicating the incorrect query.

The problem is when you get a role of reference, the XML tag for this reference is "RoleReference".

When you create a user, the XML tag that is expected for the role reference is 'Role '.

So after getting the reference to the role of the admin vCloud (VCloudType) object.

$adminRoleRefs = $sdkAdmin-> getRoleRefs ('organisation administrator');

the user must make one more step to convert the tag.

There are two ways to do this:

1. with the help of $adminRoleRefs [0]-> set_tagName ('Role');

or

2. with the help of VMware_VCloud_SDK_Helper::createReferenceTypeObj ($adminRoleRefs [0]-> get_href());

I will record a bug in development of the SDK for this question.

Thank you

Kimberly

Tags: VMware

Similar Questions

Maybe you are looking for

  • Satellite A660 - 17 M - need drivers for Windows 7 32 bit

    Dear all I just brought a new Toshiba Satellite A660 - 17 M in Egypt and I installed windows 7 32-bit on it to support my company work, but I could find the drivers for it on the website and many material options does not specially the extra package,

  • I can't access the BIOS to change the boot on Satellite 2410 order

    I can't access the CMOS change boot priorityre. Help! Laptop Satellite S2410-504. I try normally press 'C' at startup to boot from the CD-ROM. but it does not work.F12 do not help too.I think that some define some password on HWUtility, but how to di

  • What is the best? Windows 7 or vista

    Which of the two above gives fewer complications? These days most people are turning to Windows 7. is it useful?

  • Install HP laserjet 1300 Windows XP, SP3,

    When you try to install the HP Laserjet 1300 on Windows XP, SP3, I get an error message and the process rollsback.  The message is "Cannot install this hardware there was a problem installing this hardware, HP LASERJET 1300 PCL 6, an error occurred d

  • Want to download Personal Web Server for Windows Vista

    Hello, where can I download Personal Web Server for Windows Vista Home Premium 32-bit? I can only find downloads for Win - 98. Thanks for any help.