ManagementClient assignRolestoUser fails with Bad Request Invalid request payload input

Hello after creating a new user using the Management Client api I immediately try and set them into a role, but this fails with the payload error. Is it because I cannot immediately add a user to a role after creation?

const scope = "read:users update:users create:users read:logs_users read:grants read:roles create:roles update:roles create:role_members read:role_members create:organization_member_roles read:organization_member_roles";
const authClient = new ManagementClient({
  domain: AUTH0_DOMAIN,
  clientId: AUTH0_CLIENT_ID,
  clientSecret: AUTH0_CLIENT_SECRET,
  scope
});
const CONNECTION = "something";
authClient.createUser({
        email: request.body.email,
        name: request.body.email,
        password: request.body.password,
        given_name: request.body.firstName,
        family_name: request.body.lastName,        
        connection: CONNECTION
      })
      .then((user) => {
        console.log("user created in auth0:", user.user_id);

        authClient.assignRolestoUser(
          { id: user.user_id },
          { "roles": ["my role"] }
        )
        .then(result => {
          console.log("user added to role");
          const create_user_mutation = getCreateUserMutation({
            username: user.email,
            email: user.email,
            created: new Date().toLocaleString(),
            last_login: new Date().toLocaleString(),
            is_active: true,
            user_id: user.user_id
          });
  
          sendDataQuery(create_user_mutation)
            .then(result => {
              console.log("user created in our db", result);
              reply
                .send({
                  status: "New user created successfully"
                });
            })
            .catch(err => {
              console.log("Failed to create new internal user", err);
              reply.code(500).send(new Error("Failed to create new internal user"));
            });
        })
        .catch(err => {
          console.log("add user to role error", err);
          reply
            .code(520)
            .type("application/json")
            .send({ message: `user with email ${request.body.email} could not be added to role VSA` });
        });
      })
      .catch((err) => {
        console.log("create user error", err);
        reply
          .code(520)
          .type("application/json")
          .send({ message: `user with email ${request.body.email} could not be created` });
      });

Hi @dchoi,

Welcome to the Auth0 Community!

This error suggests there is something wrong with your request payload.

Can you please post your payload? Also, be sure you are sending role_id, not role name.