public function Users::create in Auth0 Single Sign On 8.2
Create a new User. Required scope: "create:users"
@link https://auth0.com/docs/api/management/v2#!/Users/post_users
Parameters
array $data User create data::
- "connection" name field is required and limited to sms, email, & DB connections.
- "phone_number" field is required by sms connections.
- "email" field is required by email and DB connections.
- "password" field is required by DB connections.
- Depending on the connection used, may also require a "username" field.
Return value
mixed|string
Throws
\Exception Thrown by the HTTP client when there is a problem with the API call.
File
- vendor/
auth0/ auth0-php/ src/ API/ Management/ Users.php, line 77
Class
- Users
- Class Users. Handles requests to the Users endpoint of the v2 Management API.
Namespace
Auth0\SDK\API\ManagementCode
public function create(array $data) {
if (empty($data['connection'])) {
throw new \Exception('Missing required "connection" field.');
}
// A phone number is required for sms connections.
if ('sms' === $data['connection'] && empty($data['phone_number'])) {
throw new \Exception('Missing required "phone_number" field for sms connection.');
}
// An email is required for email and DB connections.
if ('sms' !== $data['connection'] && empty($data['email'])) {
throw new \Exception('Missing required "email" field.');
}
// A password is required for DB connections.
if (!in_array($data['connection'], [
'email',
'sms',
]) && empty($data['password'])) {
throw new \Exception('Missing required "password" field for "' . $data['connection'] . '" connection.');
}
return $this->apiClient
->method('post')
->addPath('users')
->withBody(json_encode($data))
->call();
}