0

I'm implementating API for create users in keycloak using nestjs. Did I miss out anything? I have 2 issues here.

  1. im getting undefined in firstName and lastName
  2. AnyExceptionFilter:exception:JSON undefined even I used dummy data for firstName and lastName

Can anyone please help where I made mistake.

  async createOpsUser(body: IUserRepresentation) {
    return new Promise(async (resolve, reject) => {
      // url: http://localhost:9080/auth/realms/master/users
      const bodyReq = {
        firstName: body.firstName, // getting undefined
        lastName: body.lastName, // getting undefined
        enabled: true,
      };
      const auth = await this.getAdminAuth();
      const req = {
        url: `${this.baseUrl}/realms/${this.realmName}/users`,
        auth: {
          bearer: auth.access_token,
        },
        body: bodyReq,
        method: 'POST',
        json: true,
      };

      request(req, (err, resp, payload) => {
        if (err) {
          return reject(err);
        }
        if (resp.statusCode !== 204) {
          return reject(payload);
        }
        resolve(true);
      });
    });
  }
SKL
  • 1,243
  • 4
  • 32
  • 53
  • 1
    I think we need more context around this, can you show how `createOpsUser` is being called? `body` is most likely an empty object but without more context it will be impossible to see why – nerdy beast Dec 05 '19 at 15:50
  • Please have a look in this https://github.com/keycloak/keycloak-nodejs-admin-client/blob/master/test/users.spec.ts – Subodh Joshi Dec 07 '19 at 06:53

0 Answers0