Creating user profile via REST (C#) yields “Error 400 bad request”

Hello,

The PostAsJsonAsync returns a bad request when calling the “/api/v1/users?activate=true” web api in our PROD environment.

I can run the C# code against a DEV environment without error. Our okta admin resetted the token after granting admin access to the service account used to generate the token, no luck.

A part from the web service endpoint and the token, there are no difference in the C# between development and our real okta environment. Obvisously, I am missing some header or body element, but why?

I can create a usewr if I call the api with Postman, so the problem really lies within an additional setup required in dotnet.

Regards,

Eric

Do you have any more details about the cause of the bad request, like a full error description/summary? For example, does it say the request body is malformed or that the body was missing a required attribute for user creation?

Hello Andrea,

No, I am unable to pull more detail from the .net HTTPResponseMessage object.

reasonPhrase property only says “Bad request”

Calling code is:
HttpResponseMessage response = await ApiClient.Client.PostAsJsonAsync(“/api/v1/users?activate=true”, userModel);

Client initialization is:
Client = new HttpClient();
Client.BaseAddress = new Uri(ourCorpEnv);
Client.DefaultRequestHeaders.Accept.Clear();
Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));
AuthenticationHeaderValue auth = new AuthenticationHeaderValue(“SSWS”, “generated token”);
Client.DefaultRequestHeaders.Authorization = auth;

If the .NET HTTPREsponseMessage won’t return that information, what about if you check the raw network calls being made on this machine? That way you can see the full response body. You should get more information back from Okta about the cause of the 400.

PS, we usually expect Content-Type to be set to application/json, so it could be as simple as that header missing.

Hello Andrea, thanks for replying quickly.

I finally found the problem after reviewing every lines of code (not a big project anyway). I had a custom user profile property field in the DEV environment not found in the PROD; winded up not using it after all and it was not reference in the userModel property assigned… but since it exists in the class definition, the json initialized does refer to it. So DEV was happy, but PROD was getting a request with an unknown property reference.

Little details…

ah hah!! that will do it

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