Getting The request body was not well-formed

gettin this error when attempting to create a new user via API. Using express and bodyParser to parse form body, serialize it into JSON, and then send it to OKTA. tried various formats, but all the same. What am I missing?

'{"profile":
{
"firstName":"Peter",
"lastName":"Parker",
"email":"pparker@mailinator.com",
"login":"pparker@mailinator.com"
},
"groupIds":[
"00giqta1l0kbfK1QO0h7",
"00gj0t0ieicAW2Iss0h7"
]}'

my code:

 req.body.user.profile.login = req.body.user.profile.email;
  let data = JSON.stringify(req.body.user)
rp.post({
    uri: `https://dev-451953.oktapreview.com/api/v1/users`,
    json: true,
    headers: {Authorization: `SSWS ${process.env.OKTA_TOKEN}`},
    body: `'${data}'`
  })

the error:

StatusCodeError: 400 -
 {"errorCode":"E0000003",
"errorSummary":"The request body was not well-formed.",
"errorLink":"E0000003",
"errorId":"oaeus1TJwgrSI2dKIPypAmZVA",
"errorCauses":[]}

So i’ve noticed that if I remove the groups then it works fine…

Are you creating a user or updating one? Setting the groupIds field only works when creating a new user. For existing users you can use this: https://developer.okta.com/docs/api/resources/groups#add-user-to-group

I am creating a user from scratch, which is reflected in the URI. I even tried the example provided on Okta’s page using Postman and it failed.

solved my issues by updating the groups later. not sure what’s going on.

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