我正在尝试以下代码as mentioned here,
public string loginApi(string usr, string pwd)
{
// we set the api client in global config when we configured the client
ApiClient apiClient = Configuration.Default.ApiClient;
string authHeader = "{\"Username\":\"" + usr + "\", \"Password\":\"" + pwd + "\", \"IntegratorKey\":\"" + INTEGRATOR_KEY + "\"}";
Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
// we will retrieve this from the login() results
string accountId = null;
// the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
AuthenticationApi authApi = new AuthenticationApi();
LoginInformation loginInfo = authApi.Login();
// find the default account for this user
foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
{
if (loginAcct.IsDefault == "true")
{
accountId = loginAcct.AccountId;
break;
}
}
if (accountId == null)
{ // if no default found set to first account
accountId = loginInfo.LoginAccounts[0].AccountId;
}
return accountId;
}
它无法正常工作,我用try catch包裹它并发现了这个错误,
Error calling Login: {
"errorCode": "PARTNER_AUTHENTICATION_FAILED",
"message": "The specified Integrator Key was not found or is disabled."
}
当我看着小提琴手时,
请求将转到www.docusign.net,我希望将其发送到https://demo.docusign.net
。如何更改此代码的Base Uri?
答案 0 :(得分:5)
好的,弄明白了这个问题。错误消息具有误导性。
第1步 - 似乎我需要构建配置对象。
ApiClient client = new ApiClient(basePath: "https://demo.docusign.net/restapi");
Configuration cfg = new Configuration(client);
第2步 - 需要设置auth标头
cfg.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
步骤3将其传递给Api的构造函数
AuthenticationApi authApi = new AuthenticationApi(cfg);