Okta api asp dot net core

Hello everyone, I need help I’m trying to create a user from then my asp dot net core api, I get this error “{“errorCode”:“E0000003”,“errorSummary”:“The request body was not well-formed.”,“errorLink”:“E0000003”,“errorId”:“oaeXr_VDevGS7uklyDo8J9MEg”,“errorCauses”:}” I don’t know what I did wrong can someone help .

[HttpPost(Name = "CreateUser")]
public async Task<IActionResult> CreateUser([FromBody] UserCreationRequest userRequest)
{
    try
    {
        var client = _httpClientFactory.CreateClient();

        var json = JsonConvert.SerializeObject(userRequest);
        var postData = new StringContent(json, Encoding.UTF8, "application/json");

        var YourOktaDomain = _oktaOptions.Value.OktaDomain;

        var request = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{YourOktaDomain}/api/v1/users?activate=true");
        request.Headers.Add("Accept", "application/json");
        request.Headers.Add("Authorization", $"SSWS {_oktaOptions.Value.ApiToken}");

        var response = await client.SendAsync(request);

        if (response.IsSuccessStatusCode)
        {
            var response1 = await response.Content.ReadAsStringAsync();
            return Ok(response1);
        }
        else
        {
            var errorMessage = await response.Content.ReadAsStringAsync();
            return StatusCode((int)response.StatusCode, errorMessage);
        }

    }
    catch (Exception ex)
    {
        return StatusCode(500, ex.Message);
    }
}

You might have an easier time using our dedicated .NET Management SDK. It will handle the auth for you and has built in methods that you can use for user creation.

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