Closed ctmckenna closed 8 years ago
Hi @ctmckenna, are you testing all of this with a production account or are you using a developer sandbox account created through the dev center?
In any case I think some of the confusion is due to terminology here - when instantiating the api client you actually set the basePath
of the REST API you're using, not the baseUrl
returned from the login call for a given user. That information (such as the actual baseUrl your account/user resides on) is actually encapsulated from you as a caller of this java client - all you have to do is tell the client what environment you're using and it should take care of the underlying URL paths, etc.
For instance, if you are testing with a developer sandbox account (which operates in the demo environment) you would do:
apiClient.setBasePath("https://demo.docusign.net/restapi");
Otherwise, if you've purchased an account and are live in production then you would do
apiClient.setBasePath("https://www.docusign.net/restapi");
Please give that a try (based on what environment you're using) and let us know if that doesn't work.
Cheers, -Ergin
Thanks @Ergin008, do you mind pointing me to the code that encapsulates the actual baseUrl my account resides on? From what I can see, nothing changes ApiClient's basePath internally.
For some reason I get a USER_AUTHENTICATION_FAILED error from the following code in the production environment (but it works in the developer sandbox using the sanbox base path).
apiClient.setBasePath("https://www.docusign.net/restapi");
apiClient.addDefaultHeader("X-DocuSign-Authentication", "{\"Username\":\"" + email + "\",\"Password\":\"" + password + "\",\"IntegratorKey\":\"" + integratorKey + "\"}");
Configuration.setDefaultApiClient(apiClient);
try {
AuthenticationApi authenticationApi = new AuthenticationApi();
String accountId = authenticationApi.login().getLoginAccounts().get(0).getAccountId();
EnvelopesApi envelopesApi = new EnvelopesApi();
return envelopesApi.getDocument(accountid, envelopeId, "combined");
} catch (Exception e) {}
The getDocument api call works when I manually parse out the hostname from the LoginAccount:
apiClient.setBasePath("https://na2.docusign.net/restapi");
@ctmckenna The basePath does not actually change once you set it, what I mean is client creates the appropriate URL needed for a given API call by appending the basePath to the URI for a given call. You do not have to explicitly do that yourself, the client takes care of it for you.
If you're saying the code works in Demo but does not work in production then - based on the error message you're getting - I would guess you don't have a valid production account? Have you purchased an API Plan for instance or are you testing with a free trial account or something of that nature? If you purchased an API Plan then you'll need to pass Certification before you can use that production account with the API.
More info here: https://secure.docusign.com/developer
@Ergin008 It says here that we need to change the base url to the one returned from "/login_information": https://www.docusign.com/p/RESTAPIGuide/RESTAPIGuide.htm#GettingStarted/REST API Base URL.htm%3FTocPath%3DGetting%2520Started%7C_____5 The link seems to be correct because when I dont use that baseUrl, I get a USER_AUTHENTICATION_FAILED error.
You said earlier that "the actual baseUrl your account/user resides on is actually encapsulated from you as a caller of this java client", and I asked where this happens in the code because I'm not seeing it. When I call login() in AuthenticationApi.java on production, the baseUrl returned is "https://na2.docusign.net/restapi". Only when I manually update ApiClient.java's baseUrl to this new value am I able to use the production API. I'm commenting here because I agree that this should be encapsulated within ApiClient.java, and it looks like the code expects it to work that way, especially since there's no mention of the returned baseUrl in CoreRecipes.java. Would you mind pointing me to the place where this is supposed to happen?
It seems like others have had to do this as well. Here's a client library that does use the baseUrl returned from /login_information: https://github.com/Ergin008/eSignJavaLib/blob/master/src/com/docusign/esignature/DocuSignClient.java
@Ergin008 not sure why this is closed ?
All the REST API guide docs say that you need to obtain the login information to get the baseUrl and use that on subsequent API calls. If you don't use the right server URL (e.g. NS1/NS2/EU etc..) your calls may not go through.
I understand the base path is either http://demo.docusign.net/restapi (sandbox) or http://www.docusign.net/restapi (prod) when getting the login information initially via the API client.
But if the SAME API client instance is THEN used with the EnvelopesApi to create an envelope without changing the base path to correspond to the baseURL in the login info, it may not work as you aren't hitting the right server for the envelopes call.
From what i can see the APIClient does not magically adjust its base path to point to the correct server NS1/NS2 etc.. after the login information is obtained, this has to be done manually. And the only way to do this is with the setBasePath() method on the API client, which won't actually work unless you do some substring manipulation first as there is some duplication in portions of the path returned from the login account info and that constructed by the envelopes api. Example:
apiClient.addDefaultHeader("X-DocuSign-Authentication", "....");
// get login info
AuthenticationApi authenticationApi = new AuthenticationApi(apiClient);
LoginAccount loginAccount = authenticationApi.login().getLoginAccounts().get(0);
String loginBaseURL = loginAccount.getBaseUrl();
// example: say base URL returned is https://eu.docusign.net/restapi/v2/accounts/xyz
// create envelope
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
envelopesApi.createEnvelope(loginAccount.getAccountId(), envelope);
The call to create the envelope will still hit the server https://www.docusign.net/ and NOT https://eu.docusign.net, so you have to change it in the api client.
apiClient.addDefaultHeader("X-DocuSign-Authentication", "....");
// get login info
AuthenticationApi authenticationApi = new AuthenticationApi(apiClient);
LoginAccount loginAccount = authenticationApi.login().getLoginAccounts().get(0);
String loginBaseURL = loginAccount.getBaseUrl();
// example: say base URL returned is https://eu.docusign.net/restapi/v2/accounts/xyz
// update the client url
apiClient.setBasePath(loginBaseURL.substring(0,loginBaseURL.indexOf('v2/')+ 3 ... etc)
// create envelope
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
envelopesApi.createEnvelope(loginAccount.getAccountId(), envelope);
Now the envelope call will hit the EU server and not www.docusign.net.
Am i missing something ? If not, Is this going to be resolved or should this munging of the path be the acceptable solution ?
When I call authenticationApi.login().getLoginAccounts().get(0), the LoginAccount object's baseUrl is "https://na2.docusign.net/restapi/v2/accounts/[accountId]". Meanwhile EnvelopesApi appends "/v2/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}/fields" to the apiClient's baseUrl. So if I blindly set the apiClient's base url with loginAccount.getBaseUrl via
apiClient.setBasePath(loginAccount.getBaseUrl());
EnvelopesApi will issue this request: "https://na2.docusign.net/restapi/v2/accounts/{accountId}/v2/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}/fields"To use the baseUrl returned during login, it looks like i need to take a substring up to /restapi and set that as the apiClient's baseUrl (https://na2.docusign.net/restapi).
If I don't use the baseUrl returned during login, and continue using https://www.docusign.net/restapi to download an envelope pdf, I get a USER_AUTHENTICATION_FAILED error.