"400 Bad Request - Connection does not exist"

CONTEXT:

  • Using Auth0 Management SDK.
  • Using a custom M2M application User API (in the photo there’s the list of my applications)
  • The API Auth0 Management API (created by default by Auth0) authorizes some permissions/scopes (create:users delete:users read:users read:user_idp_tokens read:roles update:users) for the M2M application User API


CODE:

const {
    ManagementClient
} = require('auth0');
const auth0Management = new ManagementClient({
    domain: process.env.AUTH0_DOMAIN,
    clientId: process.env.AUTH0_CLIENT_ID_USERAPI,
    clientSecret: process.env.AUTH0_CLIENT_SECRET_USERAPI,
    scope: 'create:users delete:users read:users read:user_idp_tokens read:roles update:users'
});
...
const user = {
    email: 'john.doe@gmail.com',
    phone_number: '+199999999999999',
    user_metadata: {},
    blocked: false,
    email_verified: false,
    phone_verified: false,
    app_metadata: {},
    given_name: 'John',
    family_name: 'Doe',
    name: 'John Doe',
    nickname: 'Johnny',
    picture: 'https://secure.gravatar.com/avatar/15626c5e0c749cb912f9d1ad48dba440?s=480&r=pg&d=https%3A%2F%2Fssl.gstatic.com%2Fs2%2Fprofiles%2Fimages%2Fsilhouette80.png',
    user_id: 'test|1234567890',
    connection: 'Initial-Connection',
    password: 'Asdfs-f951',
    verify_email: false,
    username: 'johndoe'
};
await auth0Management.createUser(user);
...


PROBLEM:
When I try to create a user with Auth0 SDK, I receive this message:

name: 'Bad Request',
message: 'The connection does not exist.',
statusCode: 400,
requestInfo: {
        method: 'post',
        url: 'https://<my tenant name>.auth0.com/api/v2/users'
},
originalError: {
        Error: Bad Request
        at Request.Object. < anonymous > .Request.callback(D: \Codi\ Code\ au\ node_modules\ superagent\ lib\ node\ index.js: 706: 15)
        at parser(D: \Codi\ Code\ au\ node_modules\ superagent\ lib\ node\ index.js: 916: 18)
        at Stream.res.on(D: \Codi\ Code\ au\ node_modules\ superagent\ lib\ node\ parsers\ json.js: 19: 7)
        at emitNone(events.js: 106: 13)
        at Stream.emit(events.js: 208: 7)
        at Unzip.unzip.on(D: \Codi\ Code\ au\ node_modules\ superagent\ lib\ node\ unzip.js: 55: 12)
        at emitNone(events.js: 111: 20)
        at Unzip.emit(events.js: 208: 7)
        at endReadableNT(_stream_readable.js: 1064: 12)
        at _combinedTickCallback(internal / process / next_tick.js: 138: 11)
        at process._tickCallback(internal / process / next_tick.js: 180: 9)
     status: 400,
     response:
     Response {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        res: [Object],
        request: [Object],
        req: [Object],
        text: '{"statusCode":400,"error":"Bad Request","message":"The connection does not exist.","errorCode":"inexistent_connection"}',
        body: [Object],
        files: undefined,
        buffered: true,
        headers: [Object],
        header: [Object],
        statusCode: 400,
        status: 400,
        statusType: 4,
        info: false,
        ok: false,
        redirect: false,
        clientError: true,
        serverError: false,
        error: [Object],
        created: false,
        accepted: false,
        noContent: false,
        badRequest: true,
        unauthorized: false,
        notAcceptable: false,
        forbidden: false,
        notFound: false,
        unprocessableEntity: false,
        type: 'application/json',
        charset: 'utf-8',
        links: {},
        setEncoding: [Function: bound],
        redirects: []
       }
     }

QUESTION:
What is the cause of the problem?

1 Like

have you enabled your application “User API” for this connection? Go to Initial-Connection > Applications tab and turn on the toggle for User API application.

Users are created per connection. Think database users, facebook users, google users etc. Enabling M2M application for Auth0 management API only allows them to call the management api but you haven’t enabled a connection for the application.

1 Like

RESOLVED

The word connection was strange for me. It isn’t related to the meaning of databases.

I just put the name of my Auth0 Database on connection: "guillemau-test" in user object during POST Create User.

Here there’s the name of connections for each user (the new user already created is John.

The docs of Auth0 Management API should have to be more clear about what is connection.

Thanks @ashish for making me aware of connection!

1 Like

Glad to hear you have it working now @guillempuche!

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