Creating a Connection
This topic explains how to connect the Digital.ai Agility with .NET SDK.
Overview
Connecting to the Digital.ai Agility API via the .NET SDK involves determining the URL of your Agility instance, determiningthe API authentication type that you want use, determining your proxy credentials (if you use one), and then building a connection object. To build a connection object you'll use the V1Connector class which is implemented using a fluent builder interface.
Here's an example of how to use the V1Connectorwith an access token:
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.Build();
A few things to point out abut the V1Connector:
- The Server Base URIis the URL that you use for your Agility instance and is typically in the form of "http(s)://server name/instance name".
- The user agent header is used to pass the name and version number of your application to the API which can help with log analysis should there be an issue.
- The Build method is the builder's terminating method and returns the V1Connector object which you will then pass to other objects when performing actions with the API.
Access Tokens is the preferred connection method.
The V1Connectoris a new connector released with the 15.0.0.0 version of the .NET SDK. It replaces all other legacy connectors like V1APIConnector andVersionOneAPIConnector. The legacy connectors are still available for use within the SDK but have been marked for deprecation. They will be removed in a future release.
Connecting with Basic Authentication
When using Basic authentication, you use theWithUsernameAndPasswordmethod, passing in the username and password of the VersionOne member account that you want to connect with:
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithUsernameAndPassword("username", "password")
.Build();
Connecting with Windows Integrated Authentication
When using Windows Integrated Authentication, you use theWithWindowsIntegratedmethod. If you want to use the SDK with the currently logged in user's account, you do not need to pass any parameters:
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithWindowsIntegrated()
.Build();
If you need to use the account of a specific user, you can use the overloaded version of the WithWindowsIntegrated method, passing in the fully qualified domain\username and password of the user's account:
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithWindowsIntegrated("DOMAIN\\username", "password")
.Build();
Connecting with Access Tokens
When using Access Token Authentication,you use theWithAccessTokenmethod, passing in the access token associated with the VersionOne member account that you want to connect with:
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.Build();
When trying to use an access token when your VersionOne instance has been configured to use Windows Integrated Authentication, you will need to use the special UseOAuthEndpointsmethod of the connector. This method allows the connectorto bypass NTLM and authenticate directly to the API with an access token.
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.UseOAuthEndpoints()
.Build();
Connecting with a Proxy
If you are using a proxy in your environment, you can use the WithProxy method, passing in a ProxyProviderobject hydrated with the URL, username, and password used to authenticate with the proxy:
ProxyProvider proxyProvider = new ProxyProvider(new Uri("proxyURL"), "proxyUsername", "proxyPassword");
V1Connector connector = V1Connector
.WithInstanceUrl("<Server Base URI>")
.WithUserAgentHeader("AppName", "1.0")
.WithAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.WithProxy(proxyProvider)
.Build();
You cannot use a proxy when connecting with Windows Integrated Authentication.