Last active
February 20, 2021 22:49
-
-
Save ndbroadbent/e9e8869530c195cae928b4794f0bb3b5 to your computer and use it in GitHub Desktop.
DocSpring + Zoho CRM - Examples for creating Submissions and Combined Submissions, and poll for status until they are processed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used for loop that waits for pending jobs to be processed. | |
LoopList={"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", | |
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", | |
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30"}; | |
templateID = "<TEMPLATE ID>"; | |
apiTokenId = "<API TOKEN ID>"; | |
apiTokenSecret = "<API TOKEN SECRET>"; | |
base64EncodedLogin = zoho.encryption.base64Encode(apiTokenId + ":" + apiTokenSecret); | |
headerMap = Map(); | |
headerMap.put("Content_Type","application/json"); | |
headerMap.put("Authorization","Basic " + base64EncodedLogin); | |
combinedSubmissionsRequestMap = zoho.encryption.urlDecode('{"source_pdfs": [{ "type": "submission", "id": "<SUBMISSION ID 1>" }, { "type": "submission", "id": "<SUBMISSION ID 2>" }]}'); | |
// API Reference: https://docspring.com/docs/api/combine_pdfs.html | |
combinedSubmissionResponse = postUrl("https://api.docspring.com/api/v1/combined_submissions", combinedSubmissionsRequestMap, headerMap); | |
combinedSubmissionId = combinedSubmissionResponse.getJSON("combined_submission").getJSON("id"); | |
combinedSubmissionState = combinedSubmissionResponse.getJSON("combined_submission").getJSON("state"); | |
getCombinedSubmissionResponse = null; | |
for each index indexItem in LoopList | |
{ | |
if (combinedSubmissionState == "pending") | |
{ | |
// Zoho Deluge doesn't have any "sleep" or "delay" function, | |
// so we can use this web service to add a 1 second delay between requests. | |
getUrl("https://httpstat.us/200?sleep=1000"); | |
getCombinedSubmissionResponse = getUrl("https://api.docspring.com/api/v1/combined_submissions/" + combinedSubmissionId, headerMap); | |
combinedSubmissionState = getCombinedSubmissionResponse.getJSON("state"); | |
} | |
} | |
if (combinedSubmissionState != "processed") | |
{ | |
info "Something went wrong! Combined Submission " + combinedSubmissionId + " state was: " + combinedSubmissionState; | |
} | |
else | |
{ | |
downloadUrl = getCombinedSubmissionResponse.getJSON("download_url"); | |
info "Combined Submission " + combinedSubmissionId + " state was: " + combinedSubmissionState + ". Download URL: " + downloadUrl; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used for loop that waits for pending jobs to be processed. | |
LoopList={"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", | |
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", | |
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30"}; | |
templateID = "<TEMPLATE ID>"; | |
apiTokenId = "<API TOKEN ID>"; | |
apiTokenSecret = "<API TOKEN SECRET>"; | |
base64EncodedLogin = zoho.encryption.base64Encode(apiTokenId + ":" + apiTokenSecret); | |
headerMap = Map(); | |
headerMap.put("Content_Type","application/json"); | |
headerMap.put("Authorization","Basic " + base64EncodedLogin); | |
requestMap = zoho.encryption.urlDecode('{"data": {"name": "<TEST DATA>"}}'); | |
// API Reference: https://docspring.com/docs/api/generate_pdf.html | |
createSubmissionResponse = postUrl("https://api.docspring.com/api/v1/templates/" + templateID + "/submissions", requestMap, headerMap); | |
submissionId = createSubmissionResponse.getJSON("submission").getJSON("id"); | |
submissionState = createSubmissionResponse.getJSON("submission").getJSON("state"); | |
getSubmissionResponse = null; | |
for each index indexItem in LoopList | |
{ | |
if (submissionState == "pending") | |
{ | |
// Zoho Deluge doesn't have any "sleep" or "delay" function, | |
// so we can use this web service to add a 1 second delay between requests. | |
getUrl("https://httpstat.us/200?sleep=1000"); | |
getSubmissionResponse = getUrl("https://api.docspring.com/api/v1/submissions/" + submissionId, headerMap); | |
submissionState = getSubmissionResponse.getJSON("state"); | |
} | |
} | |
if (submissionState != "processed") | |
{ | |
info "Something went wrong! Submission " + submissionId + " state was: " + submissionState; | |
} | |
else | |
{ | |
downloadUrl = getSubmissionResponse.getJSON("download_url"); | |
info "Submission " + submissionId + " state was: " + submissionState + ". Download URL: " + downloadUrl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment