ASP.NET Core HttpClient POST call to okta user api failed

Hi,

I am working on a project with OKTA users/groups api. I am trying to add/edit user/group in OKTA user management through .NET Core httpclient calls. But it failed in all user/user data, and gives error message “The request body was not well-formed.” always even when i have proper data.

Here is the code i am using.

var uri = “https://.oktapreview.com/api/v1/users?activate=true”;
using (var client = new HttpClient())
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(uri)
};
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));
request.Headers.Authorization = new AuthenticationHeaderValue(“SSWS”, “”);
request.Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, “application/json”);
var response = await client.SendAsync(request);
var result = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject(result);
}

data: {“Id”:null,“Status”:null,“Profile”:{“FirstName”:“demo”,“LastName”:“user”,“Email”:“demo.user12@crayon.com”,“Login”:“demo.user12@crayon.com”,“MobilePhone”:“1111111111”,“Department”:“Art”}}

OKTA Error: {“errorCode”:“E0000003”,“errorSummary”:“The request body was not well-formed.”,“errorLink”:“E0000003”,“errorId”:“oae2ca8eNAcRr6ahe4kgifAzg”,“errorCauses”:[]}

The same request is working fine in POSTMAN, its wired and surprise.

Someone can check this and give me a solution.

Thanks

Hi @Pandi

Can you please open a support ticket with us at support@okta.com in order to have this further investigated?

Thanks, @dragos. I found a solution for the reported problem. Serialize the payload using CamelCaseProperty resolver fixes the issue.

JsonConvert.SerializeObject(payload, new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
})

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