Skip to navigation

IAM SDK - C# (beta)

View as Markdown

The Docusign Intelligent Agreement Management (IAM) SDKs assist developers in using the Intelligent Agreement Management (IAM) APIs, simplifying common tasks.

This page offers high-level information about the C# SDK and its usage.

APIs included in this SDK

The IAM SDKs include the following APIs:

  • Workflow Builder API: Trigger and manage Agreement Builder workflows from your own app.
  • Agreement Manager API: Connect AI-extracted data from agreements stored in Agreement Manager into your own app. into your own app.
  • Workspaces API: Create structured, secure, and scalable agreement workflows.
  • Connected Fields API: Discover extension apps that your app can use to validate input as part of the eSignature process.

Additional APIs may be added later; check this page for updates.

How to obtain the SDK

The easiest way to add the SDK to your project is by adding the Docusign.IAM.SDK Nuget package to your project in Visual Studio.

Adding the SDK to your project using the Visual Studio UI

  1. Open Visual Studio and load the solution you wish to use.

  2. Open the Solution Explorer window and right-click the desired project in the solution.

  3. Select Manage NuGet Packages… (shown below).

    C# IAM SDK VS menu showing nuget packages option

  4. In the NuGet Package Manager window, select the Browse tab on the left.

    C# IAM SDK searching for Nuget packages

  5. In the Search textbox, enter “Docusign.IAM” to find the IAM SDK. Make sure the Include prerelease checkbox is selected.

  6. Docusign.IAM.SDK by Docusign (publisher) should be displayed first in the search results. Select it.

    C# IAM SDK VS found Nuget package to add

  7. Select Install to install the latest version of the package.

  8. Acknowledge the license agreement by selecting I Accept on the License Acceptance screen.

You have now successfully downloaded, configured, and installed the Docusign IAM SDK for your project. To confirm the package is available in your project, you can go back to the Solution Explorer window and expand the Dependencies > Packages section of the project. You should see Docusign.IAM.SDK (version number) listed.

VS Explorer showing added C# IAM SDK

Note: If you expand the Docusign.IAM.SDK package, you will see the additional dependencies that are automatically installed by the NuGet package manager.

Adding the C# SDK to your project using the command line

  1. Open the NuGet Package Manager command line from the Visual Studio menu bar by selecting Tools > NuGet Package Manager > Package Manager Console.

  2. From the Package Manager Console, run the following command:

    dotnet add package Docusign.IAM.SDK

    The command above will automatically install the latest stable version. If desired, you can specify a specific version by using the -Version switch. For example, this command installs version 1.0.0 of the Docusign C# IAM package:

    dotnet add package Docusign.IAM.SDK --version 1.0.0

Getting started with the C# IAM SDK

The best way to learn how to use the C# IAM SDK is to explore the code examples provided by Docusign. You can find the C# code examples in the code-examples-csharp public github repository.

These code examples can also be part of the ZIP file downloaded when you use the Quickstart. This tool will also create all the necessary configuration data in your developer account so you’ll be ready to run it.

Authentication support

Every API call must be authenticated. The C# IAM SDK provides functionality to simplify the use of authentication for making IAM API calls.

Obtaining an access token

Before you begin the authentication process, you must create and configure your app. Specifically:

  • Create your app and obtain your integration key (client ID).
  • Generate a client secret for your app.
  • Add your redirect URI to the list of allowed redirect URLs associated with your integration Key.

These settings are required to obtain an authorization code and exchange it for an access token in the steps below, which demonstrate the Confidential Authorization Code Grant flow. Other OAuth flows may require different configuration settings.

Step 1: Obtain authorization code

If this is the first time this application is requesting an authorization code from this user, the user will be asked to provide consent. Docusign will then redirect them to your specified redirect URI with an authorization code included as a query parameter named code.

C#
// before using this code, make sure your .env has “DOCUSIGN_CLIENT_ID” which is your IK (GUID)that you created as well as the “DOCUSIGN_REDIRECT_URI” which is the URI to redirect the browser after authentication.
using System;
using Docusign.IAM.SDK;
using Docusign.IAM.SDK.Models.Components;
using Docusign.IAM.SDK.Utils.Auth;
// Create the authorization URL
String consentUrl = AuthorizationUrlBuilder.Create()
.WithBasePath(OAuthBasePath.Demo)
.WithResponseType(AuthorizationUrlResponseType.Code)
.WithClientId(Environment.GetEnvironmentVariable("DOCUSIGN_CLIENT_ID"))
.WithRedirectUri(Environment.GetEnvironmentVariable("DOCUSIGN_REDIRECT_URI"))
.Build();
// Direct the user to grant consent
Console.WriteLine(
$"Please visit the following URL to authorize the application:{consentUrl}"
);

Step 2: Exchange Authorization Code for Access Token

After you obtain the authorization code, you need to use it to get an access token. The SDK provides helper functions to simplify this process.

C#
// before using this code, make sure your .env has “DOCUSIGN_CLIENT_ID” which is your IK (GUID)that you created as well as the “DOCUSIGN_CLIENT_SECRET” which you can create together with the IK.
using Docusign.IAM.SDK;
using Docusign.IAM.SDK.Models.Components;
using Docusign.IAM.SDK.Models.Requests;
using Docusign.IAM.SDK.Models.Errors;
using System;
using System.Threading.Tasks;
try
{
// Create an unauthenticated client to exchange the auth code for a token
var anonClient = IamClient.Builder().Build();
// Prepare the request with the auth code
var request = new ConfidentialAuthCodeGrantRequestBody()
{
Code = authCode,
};
// Get token using client credentials
var res = await anonClient.Auth.GetTokenFromConfidentialAuthCodeAsync( security: new GetTokenFromConfidentialAuthCodeSecurity()
{
ClientId = Environment.GetEnvironmentVariable("DOCUSIGN_CLIENT_ID"),
SecretKey = Environment.GetEnvironmentVariable("DOCUSIGN_CLIENT_SECRET"),
},
request: request
);
/**
* Use the token response as needed. E.g.:
* - Store the access token and refresh token in a database
* - Use the access token to make API calls
* - Show the user a success message
**/
Console.WriteLine("Access Token: " + res.AuthorizationCodeGrantResponse.AccessToken);
}
catch (OAuthErrorResponse e)
{
// Handle OAuth error
Console.WriteLine("OAuth Error: " + e.ErrorDescription);
}

Using an access token

Once you have obtained an access token, you can use it to make API calls this way:

C#
using Docusign.IAM.SDK;
// Initialize the SDK with your access token
var sdk = IamClient
.Builder()
.WithAccessToken("<YOUR_ACCESS_TOKEN_HERE>")
.Build();
// Make API call to get the basePath as well as account information for the user
var res = await sdk.Auth.GetUserInfoAsync();

Open source repository

The source being used to build the C# IAM SDK is available publicly in the following repository on our public GitHub: https://github.com/docusign/docusign-iam-csharp-client You can use it to build your own version of the SDK.

Compatibility

The C# IAM SDK requires .NET version 8.0 or above.

Code examples

You can find code examples showcasing how to use the IAM SDK with Agreement Builder API, Connected Fields API, and Agreement Manager API in the code-examples-csharp repo.

Providing feedback about the SDK

To provide feedback on the SDK, please either submit an issue in the GitHub repository or send an email to developers@docusign.com.