Last active
May 30, 2020 18:11
-
-
Save ndbroadbent/7dc7b42f924258456727e7b549fcaa28 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
set -e | |
TEMPLATE_ID="tpl_q56GMFtgY6JEEfzASd" | |
API_TOKEN_ID="api_test_7tKsjEfES39ENnNThX" | |
API_TOKEN_SECRET="EvpFND320XPPffPHz2OSrGISg2x1Ms0zjoX8FPfPgng" | |
read -r -d '' SUBMISSION_DATA <<'JSON' | |
{ | |
"data": { | |
"first_name":"Jillian", | |
"last_name":"Witting", | |
"signature":{ | |
"text": { "name": "velit commodo fugiat", "typeface": "Satisfy" } | |
} | |
}, | |
"test": true, | |
"metadata": {} | |
} | |
JSON | |
create_submission() { | |
curl -s "https://api.docspring.com/api/v1/templates/${TEMPLATE_ID}/submissions" \ | |
-X POST \ | |
-u "${API_TOKEN_ID}:${API_TOKEN_SECRET}" \ | |
-d "$SUBMISSION_DATA" | |
} | |
fetch_submission() { | |
curl -s "https://api.docspring.com/api/v1/submissions/${SUBMISSION_ID}" \ | |
-u "${API_TOKEN_ID}:${API_TOKEN_SECRET}" | |
} | |
parse_json_value() { | |
echo "$1" | grep "\"$2\":" | sed -n 's/.*": *"\(.*\)".*/\1/p' | |
} | |
echo "Generating PDF for ${TEMPLATE_ID}..." | |
SUBMISSION_RESPONSE="$(create_submission)" | |
SUBMISSION_ID="$(parse_json_value "$SUBMISSION_RESPONSE" id)" | |
SUBMISSION_STATE="$(parse_json_value "$SUBMISSION_RESPONSE" state)" | |
echo "Waiting for submission $SUBMISSION_ID to be processed..." | |
while [[ "$SUBMISSION_STATE" = "pending" ]]; do | |
SUBMISSION_RESPONSE="$(fetch_submission)"; | |
SUBMISSION_STATE="$(parse_json_value "$SUBMISSION_RESPONSE" state)" | |
sleep 1 | |
done | |
if [[ "$SUBMISSION_STATE" = "processed" ]]; then | |
echo "$SUBMISSION_RESPONSE" | |
echo "Download your PDF:" | |
parse_json_value "$SUBMISSION_RESPONSE" download_url | |
echo | |
else | |
echo 'Sorry, something went wrong!' | |
echo "$SUBMISSION_RESPONSE" | |
fi |
This file contains hidden or 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
curl -s "http://app.docspring.com/templates/tpl_q56GMFtgY6JEEfzASd/curl_example.sh" \ | |
-o "/tmp/docspring_tpl_q56GMFtgY6JEEfzASd.sh" | |
bash "/tmp/docspring_tpl_q56GMFtgY6JEEfzASd.sh" |
This file contains hidden or 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
Generating PDF for tpl_q56GMFtgY6JEEfzASd... | |
Waiting for submission sub_eEsRgHyQk54NDzsrba to be processed... | |
{ | |
"id": "sub_eEsRgHyQk54NDzsrba", | |
"template_id": "tpl_q56GMFtgY6JEEfzASd", | |
"batch_id": null, | |
"state": "processed", | |
"test": true, | |
"editable": null, | |
"expired": false, | |
"expires_at": null, | |
"json_schema_errors": [], | |
"metadata": {}, | |
"processed_at": "2020-05-30T18:06:32Z", | |
"data_requests": [], | |
"pdf_hash": "b1de6d73117dcce175a8619a70851e966cf13b808ea612fecb2eec870758a961", | |
"download_url": "https://production-formapi-docs.s3.amazonaws.com/store/acc_fEgPKYHn2YtGQRnx9L/templates/tpl_q56GMFtgY6JEEfzASd/submissions/sub_eEsRgHyQk54NDzsrba.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJESVN6QC4ACN3XSQ%2F20200530%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200530T180632Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=653cf477e14c49615afb818e06049771ad39ceb6cedd45478c86b3c6c4adcce1", | |
"permanent_download_url": "https://app.docspring.com/submissions/sub_eEsRgHyQk54NDzsrba/download", | |
"actions": [] | |
} | |
Download your PDF: | |
https://production-formapi-docs.s3.amazonaws.com/store/acc_fEgPKYHn2YtGQRnx9L/templates/tpl_q56GMFtgY6JEEfzASd/submissions/sub_eEsRgHyQk54NDzsrba.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJESVN6QC4ACN3XSQ%2F20200530%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200530T180632Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=653cf477e14c49615afb818e06049771ad39ceb6cedd45478c86b3c6c4adcce1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment