<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content

How To Make Direct Okta API Calls with okta-sdk-dotnet

Okta Classic Engine
Okta Identity Engine
SDKs & Libraries

Overview

Okta Management SDKs may not implement all of the Okta API endpoints or may not pull in the attributes an application is interested in.
okta-sdk-dotnet provides a way to manually call these endpoints.

Applies To

Cause

Some of the Okta API endpoints may not be exposed in the SDKs, or may change and the latest SDK version has yet to account for this change. Being able to make direct calls to these API allows applications to continue to use the SDK for all management calls.

Solution

Below is a code snippet needed to make a call using the SDK.

            using Newtonsoft.Json.Linq;
            using Okta.Sdk.Api;
            using Okta.Sdk.Client;
            ...
            ...

            Okta.Sdk.Client.RequestOptions localVarRequestOptions = new Okta.Sdk.Client.RequestOptions();
            localVarRequestOptions.HeaderParameters.Add("Content-Type", "application/json");
            localVarRequestOptions.HeaderParameters.Add("Accept", "application/json");
            localVarRequestOptions.PathParameters.Add("userId", "00u8mfo4xwwL88888888");
            // Authorization header will be in form of 'Authorization: YOUR_API_KEY_HERE'
            localVarRequestOptions.HeaderParameters.Add("Authorization", config.GetApiKeyWithPrefix("Authorization"));
            var path = "/api/v1/users/{userId}/factors";
            
            // I use ApplicationApi, but you can use any of the SDK APIs to get access to AsynchronousClient such as UserFactorApi
            ApiResponse<JArray> localVarResponse = await appApi.AsynchronousClient.GetAsync<JArray>(path, localVarRequestOptions).ConfigureAwait(false);
            foreach (JObject f in localVarResponse.Data)
            {
                Console.WriteLine("id: " + f.GetValue("id"));
                Console.WriteLine("  name: " + f.GetValue("name"));
                Console.WriteLine("  type: " + f.GetValue("type"));
                Console.WriteLine("  key: " + f.GetValue("key"));
                Console.WriteLine("  status: " + f.GetValue("status"));
                Console.WriteLine("  link: " + f.GetValue("_links").ToObject<JObject>().GetValue("self").ToObject<JObject>().GetValue("href"));
                
                Console.WriteLine("");
            }

The response type will depend on the API used and should be cross-referenced with the Okta API documentation.
NOTE:  If unfamiliar with curl, we recommend using Postman to help with the structure of the request. 

Related References

Complete API documentation for Okta APIs can be found at:

Loading
Okta Support - How To Make Direct Okta API Calls with okta-sdk-dotnet