I have created integrator key and private/public key in docusign sandbox.
When I am trying to call api,it is giving me error.
My code is like this:
public class DocuSignExample1 {
private static final String IntegratorKey = "10048d4c-0549-434e-b224-4805b36b69e1";
private static final String UserId = "ef27e777-c6fc-4385-91ce-63dafab5385b";
private static final String privateKeyFullPath = System.getProperty("user.dir") + "/src/test/keys/docusign_private_key2.txt";
private static final String Recipient = "xxx@gmail.com";
private static final String SignTest1File = "/src/test/docs/SignTest1.pdf";
private static final String BaseUrl = "https://demo.docusign.net/restapi";
public static void main(String[] args) {
byte[] fileBytes = null;
try {
String currentDir = System.getProperty("user.dir");
Path path = Paths.get(currentDir + SignTest1File);
fileBytes = Files.readAllBytes(path);
} catch (IOException ioExcp) {
ioExcp.printStackTrace();
}
EnvelopeDefinition envDef = new EnvelopeDefinition();
envDef.setEmailSubject("Please Sign My Sample Document");
envDef.setEmailBlurb("Hello, Please Sign My Sample Document.");
Document doc = new Document();
String base64Doc = Base64.encodeToString(fileBytes, false);
doc.setDocumentBase64(base64Doc);
doc.setName("TestFile.pdf");
doc.setDocumentId("1");
List<Document> docs = new ArrayList<Document>();
docs.add(doc);
envDef.setDocuments(docs);
Signer signer = new Signer();
signer.setEmail(Recipient);
signer.setName("Sanjay");
signer.setRecipientId("1");
envDef.setRecipients(new Recipients());
envDef.getRecipients().setSigners(new ArrayList<Signer>());
envDef.getRecipients().getSigners().add(signer);
envDef.setStatus("sent");
ApiClient apiClient = new ApiClient(BaseUrl);
try {
byte[] privateKeyBytes = null;
try {
privateKeyBytes = Files.readAllBytes(Paths.get(privateKeyFullPath));
} catch (IOException e) {
e.printStackTrace();
}
if (privateKeyBytes == null)
return;
java.util.List<String> scopes = new ArrayList<String>();
scopes.add(OAuth.Scope_SIGNATURE);
OAuth.OAuthToken oAuthToken = apiClient.requestJWTUserToken(IntegratorKey, UserId, scopes, privateKeyBytes,
3600);
apiClient.setAccessToken(oAuthToken.getAccessToken(), oAuthToken.getExpiresIn());
UserInfo userInfo = apiClient.getUserInfo(oAuthToken.getAccessToken());
apiClient.setBasePath(userInfo.getAccounts().get(0).getBaseUri() + "/restapi");
Configuration.setDefaultApiClient(apiClient);
String accountId = userInfo.getAccounts().get(0).getAccountId();
EnvelopesApi envelopesApi = new EnvelopesApi();
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef);
System.out.println("EnvelopeSummary: " + envelopeSummary);
} catch (ApiException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
In above code I am just changing my account key,but not working.
I have created project with example. Here DocusignExample.java is working but DocusignExample1.java is not working.
https://gitlab.com/sanju24689/docusign
For DocusignExample,I have taken reference(key) from docusign java sdk(https://github.com/docusign/docusign-java-client/blob/master/src/test/java/SdkUnitTests.java) With that reference i have created my code and just change integratory key,api username and private key.
It's giving me error like "com.docusign.esign.client.ApiException: Error while requesting an access token: POST https://account-d.docusign.com/oauth/token returned a response status of 400 Bad Request"