See api-docs Menu

v1-v3 APIs have been deprecated

Don't worry, these APIs are deprecated, but they aren't shut off yet.

All new development with APIs should use the newest version of our API: /1. API /1 is based on RESTful principles, is secured by OAuth 2.0, and provides 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.

  $url = "";
  $request = "<user><firstname>Joe</firstname><lastname>Hansen</lastname>" .
  $headers = array('Content-type: application/xml','Content-Length: ' . strlen($request));
  $ch = curl_init();
  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);
 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.