Sign in

Quickstart

View as Markdown

From nothing to a read invoice. You need an Ocost account as its owner or accountant; the examples use $OCOST_KEY for your key.

1. Sign up

Sign up at https://app.ocost.io/auth/sign-up, or sign in. Files you send show in Files like any upload, and Ocost files, books and matches them.

2. Make a key

  1. Open Settings › API.
  2. Choose Make key, name it after its user ("Odoo production"), keep all three scopes, choose Make key.
  3. Choose Copy key. It starts with ocost_sk_ and is shown once.
Shell
export OCOST_KEY="ocost_sk_…"

3. Send a PDF

POST /public/v1/files takes the file as multipart/form-data in file; external_ref is your own id, echoed back.

curl -sS https://api.ocost.io/public/v1/files \
  -H "Authorization: Bearer $OCOST_KEY" \
  -F "file=@invoice.pdf" \
  -F "external_ref=account.move,42"

The answer is 202 Accepted:

JSON
{
  "id": "01a1b08c-6e3a-7562-8f4a-7924722667b1",
  "name": "invoice.pdf",
  "status": "received",
  "reason": null,
  "external_ref": "account.move,42",
  "documents": [],
  "sha256": "0edd5593…"
}

The same bytes again answer 200 OK with the same file, counted once. X-Ocost-Documents-Left is what your plan has left this month.

4. Poll until it is read

GET /public/v1/files/{file_id} answers the file as it is now. Poll every few seconds while status is received or reading (most PDFs take under a minute), then less often.

curl -sS https://api.ocost.io/public/v1/files/$FILE_ID \
  -H "Authorization: Bearer $OCOST_KEY"

Then documents lists what it holds; not_read and failed carry a reason (Files and statuses).

5. Read the document

GET /public/v1/files/{file_id}/document answers its first document as ocost.document.v1, each value with where it was read and how sure Ocost is (The document schema). GET /public/v1/documents/{document_id} answers any other.

curl -sS https://api.ocost.io/public/v1/files/$FILE_ID/document \
  -H "Authorization: Bearer $OCOST_KEY"

GET /public/v1/search finds documents by words and by meaning.

curl -sS -G https://api.ocost.io/public/v1/search \
  -H "Authorization: Bearer $OCOST_KEY" \
  --data-urlencode "q=office chairs" \
  --data-urlencode "kind=invoice"

Next