How can I get the ID of a newly created user? (Using Auth0 Laravel SDK)

After I created a new user with ManagementAPI, I want to get the user’s ID.

        Auth0::management()
            ->users()
            ->create(
                connection: 'Username-Password-Authentication',
                body: [
                    'name' =>  $request->name,
                    'email' =>  $request->email,
                    'password' =>  $request->password,
                    'email_verified' => true
                ]
            );

A new user is created by above code.
After that, I need to retrieve the ID of the newly created user.

How can I do that?

I’ve found a solution!

$new_user = Auth0::management()->usersByEmail()->get($request->email)->getBody()->getContents();
$new_user_id = json_decode($new_user)[0]->identities[0]->user_id;

That’s great to hear @t.fukao thanks for sharing with the community :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.