Automated Expense Reporting
Learn how to automate expense reporting by extracting structured data from receipts.
Manually entering data from receipts is a time-consuming and error-prone task. With the Scan Documents API, you can automate this process by extracting structured data from your receipts, saving you time and improving accuracy.
This guide will walk you through the process of creating an automated expense reporting solution using the Scan Documents API.
See in Postman
This guide's API calls are available as a Postman collection. You can use it to quickly test the API and see how it works.
Business Problem
Imagine you are building an expense management application. Your users need to be able to upload pictures of their receipts, and the application should automatically extract key information such as the vendor name, the date of the transaction, and the total amount.
Solution
We can solve this problem by using a combination of the Scan Documents API's features:
- Digitize Document: First, we'll digitize the receipt to improve its quality and make it easier to process.
- Extract Text: Next, we'll extract the text from the digitized receipt.
- Structured Data Extraction: Finally, we'll use the
extract-text
operation with a JSON schema to extract the required information in a structured format.
Let's get started!
Step 1: Upload the Receipt
First, upload the receipt image to the Scan Documents API.
Upload a File
Creates a new file
curl -X POST "https://api.scan-documents.com/v1/files" \
-H "x-api-key: YOUR_API_KEY" \
-F name="Receipt" \
-F file="@/path/to/your/receipt.jpg"
It will respond with a file object:
{
"id": "file_qgg1xpdhe3f4ot84",
"name": "Receipt",
"type": "image/webp",
"properties": {
"size": 11648,
"width": 250,
"height": 333
},
"task_id": null,
"created_at": "2025-08-23T15:15:04.000Z"
}
Take note of the id
from the response, as you'll need it in the next steps.
Step 2: Digitize the Receipt (optional)
To improve the accuracy of the text extraction, it's a good practice to first digitize the receipt. This involves detecting the document, warping it, and enhancing its colors.
You can do this by creating a scan
task:
Scan Document
Creates a task to scan an image file. This is an equivalent operation for detect-documents
and warp
combined, additionally it can apply effects to the scanned image.
curl -X POST "https://api.scan-documents.com/v1/image-operations/scan"
-H "x-api-key: YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{ "input": "file_ajw8fgkjlmzxrzz3", "name": "Digitized Receipt", "scan_mode": "standard", "effect": "none" }'
This will create a new, digitized image of the receipt. The id
of the generated file will be in the task's result.
{
"id": "task_xz9ud1dt9nuczdsm",
"operation": "scan",
"status": "completed",
"parameters": {
"input": "file_qgg1xpdhe3f4ot84",
"name": "Digitized Receipt",
"scan_mode": "standard",
"effect": "none"
},
"result": {
"generated_files": [
{
"id": "file_wak3m3cex63h6pak",
"name": "Digitized Receipt",
"type": "image/webp",
"properties": {
"size": 8040,
"width": 186,
"height": 313
},
"task_id": "task_xz9ud1dt9nuczdsm",
"created_at": "2025-08-23T15:15:18.000Z"
}
]
},
"callback_url": null,
"created_at": "2025-08-23T15:15:12.000Z",
"updated_at": "2025-08-23T15:15:19.000Z"
}
Step 3: Extract Structured Data
Now comes the exciting part! We'll use the extract-text
operation with a JSON schema to extract the vendor name, transaction date, and total amount from the receipt.
Here's the JSON schema we'll use:
{
"type": "object",
"properties": {
"vendor": {
"type": "string",
"description": "The name of the vendor or store."
},
"date": {
"type": "string",
"description": "The date of the transaction in YYYY-MM-DD format."
},
"total": {
"type": "number",
"description": "The total amount of the transaction."
}
},
"required": ["vendor", "date", "total"]
}
Now, let's make the API call:
Extract Text
Creates a task to extract text from a specified image file.
curl -X POST "https://api.scan-documents.com/v1/image-operations/extract-text" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "file_wak3m3cex63h6pak",
"format": "json",
"schema": {
"type": "object",
"properties": {
"vendor": {
"type": "string",
"description": "The name of the vendor or store."
},
"date": {
"type": "string",
"description": "The date of the transaction in YYYY-MM-DD format."
},
"total": {
"type": "number",
"description": "The total amount of the transaction."
}
},
"required": ["vendor", "date", "total"]
}
}'
The result of this task will be a JSON object containing the extracted data:
{
"id": "task_mlgn68yiwmeasvow",
"operation": "extract-text",
"status": "completed",
"parameters": {
"input": "file_wak3m3cex63h6pak",
"format": "json",
"schema": {
"type": "object",
"properties": {
"vendor": {
"type": "string",
"description": "The name of the vendor or store."
},
"date": {
"type": "string",
"description": "The date of the transaction in YYYY-MM-DD format."
},
"total": {
"type": "number",
"description": "The total amount of the transaction."
}
},
"required": [
"vendor",
"date",
"total"
]
}
},
"result": {
"format": "json",
"content": "{\"vendor\": \"Berghotel\\nGrosse Scheidegg\", \"date\": \"2007-07-30\", \"total\": 54.5}"
},
"callback_url": null,
"created_at": "2025-08-23T15:23:03.000Z",
"updated_at": "2025-08-23T15:23:12.000Z"
}
If we parse the content
field from the result
, we get:
{
"vendor": "Berghotel\nGrosse Scheidegg",
"date": "2007-07-30",
"total": 54.5
}
And that's it! You have successfully extracted structured data from a receipt. You can now use this data to populate your expense management application, saving your users from manual data entry.