Get started
Quickstart
Send a document, wait for it, read the answer: the three calls every Northdoc integration is built on.
Three calls: send the file, wait until it is done, read the answer. This one asks for two fields of your own; leave out the options and you get the pages and pictures alone. Everything else in these docs is a variation on this. It uses the two shell variables from Authentication.
# 1. Send the file and keep its id
RESP=$(curl -s -X POST "$NORTHDOC_API/documents" \
-H "Authorization: Bearer $NORTHDOC_KEY" \
-F file=@invoice.pdf \
-F 'options={"extraction": {"schema": {
"type": "object",
"properties": {"invoice_number": {"type": "string"}, "total": {"type": "number"}},
"required": ["invoice_number", "total"]
}}}')
DOC_ID=$(echo "$RESP" | jq -r '.id // empty')
[ -n "$DOC_ID" ] || { echo "$RESP"; exit 1; }
# 2. Check every two seconds until it is completed or failed
while :; do
BODY=$(curl -s "$NORTHDOC_API/documents/$DOC_ID" -H "Authorization: Bearer $NORTHDOC_KEY")
STATUS=$(echo "$BODY" | jq -r .status)
echo "$STATUS"
case "$STATUS" in
completed|failed) break ;;
queued|processing) sleep 2 ;;
*) echo "$BODY"; exit 1 ;;
esac
done
# 3. Read the data, the citations behind it, and any error
curl -s "$NORTHDOC_API/documents/$DOC_ID" \
-H "Authorization: Bearer $NORTHDOC_KEY" \
| jq '{data: .result.data, citations: .result.citations, error}'