Dropbox Forms API v3 contains several API calls for authentication and workflows. Here are examples of these API requests in Java. These examples use the Unirest request library.
For more information on these endpoints, please refer to the API Documentation.
Get Auth Token
static String getAuthToken() throws JSONException, UnirestException {
HttpResponse<JsonNode> response = Unirest.get("https://api.helloworks.com/v3/token/[API_KEY_ID]")
.header("Authorization", "Bearer [API KEY]")
.asJson();
JSONObject json = response.getBody().getObject().getJSONObject("data");
String token = json.getString("token");
return token;
}
Create Workflow Instance
static void createWorkflowInstance() throws JSONException, UnirestException {
String token = HelloWorks.getAuthToken();
HttpResponse<JsonNode> response = Unirest.post("https://api.helloworks.com/v3/workflow_instances")
.header("Authorization", "Bearer " + token)
.header("Content-Type", "application/x-www-form-urlencoded")
.field("workflow_id", "[WORKFLOW INSTANCE ID]")
.field("participants[signer][type]", "email")
.field("participants[signer][value]", "helloworks@example")
.field("participants[signer][full_name]", "HelloWorks Signer")
.asJson();
JSONObject json = response.getBody().getObject().getJSONObject("data");
}
Get Workflow Instance
static void getWorkflowInstance() throws JSONException, UnirestException {
String token = HelloWorks.getAuthToken();
HttpResponse<JsonNode> response = Unirest.get("https://api.helloworks.com/v3/workflow_instances/[WORKFLOW INSTANCE ID]")
.header("Authorization", "Bearer " + token)
.asJson();
JSONObject json = response.getBody().getObject().getJSONObject("data");
}
Get Workflow Instance Audit Trail
static void getAuditTrail() throws JSONException, UnirestException, IOException {
String token = HelloWorks.getAuthToken();
GetRequest request = Unirest.get("https://api.helloworks.com/v3/workflow_instances/[WORKFLOW INSTANCE ID]/audit_trail")
.header("Authorization", "Bearer " + token);
InputStream content = request.asBinary().getRawBody();
FileOutputStream fos = new FileOutputStream(new File("HW_audit_trail.pdf"));
int read = 0;
byte[] buffer = new byte[5000];
while( (read = content.read(buffer)) > 0) {
fos.write(buffer, 0, read);
}
fos.close();
content.close();
}
Get Workflow Instance Documents
static void getDocuments() throws JSONException, UnirestException, IOException {
String token = HelloWorks.getAuthToken();
GetRequest request = Unirest.get("https://api.helloworks.com/v3/workflow_instances/[WORKFLOW INSTANCE ID]/documents/[DOCUMENT ID]")
.header("Authorization", "Bearer " + token);
InputStream content = request.asBinary().getRawBody();
FileOutputStream fos = new FileOutputStream(new File("HW_document.pdf"));
int read = 0;
byte[] buffer = new byte[5000];
while( (read = content.read(buffer)) > 0) {
fos.write(buffer, 0, read);
}
fos.close();
content.close();
}
Comments
0 comments
Article is closed for comments.