-->

Docusign can't login. How to login in C# code?

2019-08-20 08:35发布

问题:

I have problem with Docusign.It says

DocuSign.eSign.Client.ApiException: 'Error calling Login: {

"errorCode": "PARTNER_AUTHENTICATION_FAILED",

"message": "The specified Integrator Key was not found or is disabled."

Here is my code

  // initialize client for desired environment (for production change to www)
            var apiClient = new ApiClient("https://demo.docusign.net/restapi");
            string username="[Email]";;
            string password="[Password]";
            string integratorKey="[IntegratorKey]";

            // configure 'X-DocuSign-Authentication' header
            var authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // login call is available in the authentication api 
            var authApi = new AuthenticationApi();
            var loginInfo = authApi.Login();

I have entered my valid username,password and integratorKey and it's not working. I have copied my integrator key from admin panel. I have generated two key both have status DEMO with grey button before word DEMO but none is working. What should I do to make it work ?What is the problem ?

回答1:

You are missing the statement Configuration.Default.ApiClient = apiClient;

See the example from the official SDK here

// initialize client for desired environment (for production change to www)
var apiClient = new ApiClient("https://demo.docusign.net/restapi");
Configuration.Default.ApiClient = apiClient;



string username="[Email]";
string password="[Password]";
string integratorKey="[IntegratorKey]";

// configure 'X-DocuSign-Authentication' header
var authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";    
Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);



// login call is available in the authentication api 
var authApi = new AuthenticationApi();
LoginInformation loginInfo = authApi.Login();


回答2:

You need to build a config object and then pass in the auth header into the AuthenticationApi like so:

var apiClient = new ApiClient("https://demo.docusign.net/restapi");
var config = new Configuration(apiClient);
var authApi = new AuthenticationApi(config);

Also in this line here, you have two semicolons:

string username="[Email]";;

Remove one of them.