Quickstart: from a key to a corrected, verified PDF
1. Mint a key
Sign in to a Business account, open Account → API, name the key for what will use it, choose how long it should live, and mint it. Copy the key then: it is shown once and cannot be shown again.
Keep it in an environment variable, beside the address of this service:
export CECO_URL=https://your-ceco-address
export CECO_API_KEY=ceco_live_…
2. Check that it works
curl -sf -H "Authorization: Bearer $CECO_API_KEY" "$CECO_URL/v1/usage"
The answer is JSON saying what the account holds. 401 invalid_api_key means the key is wrong, has expired or was revoked.
3. Correct a document
Upload a PDF, state that you are authorised to correct it, propose the correction, apply it, check its verification and download the result. CECO_PDF is the file to correct; this changes the first "tije" on its first page to "tij".
set -e
AUTH="Authorization: Bearer $CECO_API_KEY"
JSON="Content-Type: application/json"
# The first string value of a field in a JSON answer. With jq: jq -r .name
field() { grep -o "\"$1\":\"[^\"]*\"" | head -n 1 | cut -d'"' -f4; }
# Upload.
DOC=$(curl -sf -H "$AUTH" -F "file=@$CECO_PDF;type=application/pdf" \
"$CECO_URL/v1/documents" | field document_id)
# State that you are authorised to correct it. Every correction carries this.
ATT=$(curl -sf -H "$AUTH" -H "$JSON" -d "{\"document_id\":\"$DOC\"}" \
"$CECO_URL/v1/attestations" | field attestation_id)
# Propose the correction. Nothing changes yet; the answer says what would.
REQUEST="{\"page_index\":0,\"target\":{\"method\":\"text_layer\",\"find\":\"tije\",\"match_index\":0},\"replacement\":\"tij\",\"attestation_id\":\"$ATT\"}"
PROPOSAL=$(curl -sf -H "$AUTH" -H "$JSON" -d "$REQUEST" \
"$CECO_URL/v1/documents/$DOC/edits:propose")
echo "$PROPOSAL" | grep -q '"refusal":null' || { echo "refused: $PROPOSAL"; exit 1; }
# Apply exactly that proposal.
curl -sf -H "$AUTH" -H "$JSON" -o /dev/null \
-d "{\"request\":$REQUEST,\"apply\":{\"proposal_id\":\"$(echo "$PROPOSAL" | field proposal_id)\",\"confirm_token\":\"$(echo "$PROPOSAL" | field confirm_token)\"}}" \
"$CECO_URL/v1/documents/$DOC/edits"
# Check the verification passed, then download the corrected file.
PASSED=$(curl -sf -H "$AUTH" "$CECO_URL/v1/documents/$DOC/verification" \
| grep -o '"passed":[a-z]*' | head -n 1)
[ "$PASSED" = '"passed":true' ] || { echo "not verified"; exit 1; }
curl -sf -H "$AUTH" -o corrected.pdf "$CECO_URL/v1/documents/$DOC/export/download"
echo "corrected.pdf written for $DOC"
The same in Python and Node is on Examples, and every field of every answer is in the reference.
4. What to read next
- Authentication: storing and rotating keys, and when a key stops working.
- The verification model: what
passedpromises, and what it does not. - Errors and Limits, before you put it into production.