v1-v3 APIs have been deprecated.
Although these APIs are not shut off yet, all new development with APIs should use the newest version of our API if available, and the version /1 in all other cases. These later versions are based on RESTful principles, secured by OAuth 2.0, and provide JSON messages, search, pagination, sorting, and filtering.
Create a User in PHP
The PHP code below shows how you create a new user via the User API. Remember to insert your API key in the request.
<?php
$url = "https://app.onelogin.com/api/v3/users.xml";
$request = "<user><firstname>Joe</firstname><lastname>Hansen</lastname>" .
"<email>test2@user.com</email></user>";
$headers = array('Content-type: application/xml','Content-Length: ' . strlen($request));
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, 'YOUR ONELOGIN API KEY HERE');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HEADER, true);
$http_result = curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
if ($error) {
print $error;
} else {
preg_match("/Location:.*\/users\/(\d*)\.xml/", $http_result, $matches);
$id = $matches[1];
print "ID: $id\n";
}
?>
Have a Question?
Found a problem or a bug? Submit a support ticket.
Looking for walkthroughs or how-to guides on OneLogin's user and admin features? Check out the documentation in our Knowledge Base.
Have a product idea or request? Share it with us in our Ideas Portal.