# Receipt

Transform your receipt processing with Extracta’s cutting-edge document parsing capabilities. Our API is designed to automate the extraction of data from receipts, ideal for retailers, financial institutions, and any business that needs to analyze purchase data efficiently. This page guides you through using our API for receipt parsing, featuring a pre-configured request body template for immediate use.

## Why Extracta LABS for Receipt Parsing?

* **Streamline Financial Workflows**: Automate the capture and analysis of receipt data to speed up accounting processes and financial reporting.
* **Enhanced Accuracy**: Benefit from high precision OCR and data parsing technology that minimizes errors in financial analysis.
* **Custom Data Extraction**: Extract only the data you need, from transaction dates and amounts to item descriptions and merchant information.

## Getting Started

To extract data from receipts using Extracta LABS, you will need to send a `POST` request to our `/createExtraction` endpoint with a specific request body designed for receipt data. Below, we provide a template that includes predefined keys for common receipt information fields.

## Body Example for Receipt

<details>

<summary>JSON Body</summary>

```json
{
    "extractionDetails": {
        "name": "Receipt - Extraction",
        "language": "English",
        "options": {
            "hasTable": true,
            "handwrittenTextRecognition": false
        },
        "fields": [
            {
                "key": "receipt_id",
                "example": "1234567890",
                "type": "string"
            },
            {
                "key": "receipt_date",
                "description": "the invoice date in the following format yyyy-mm-dd",
                "example": "2022-01-01",
                "type": "string"
            },
            {
                "key": "merchant",
                "description": "the merchant in the invoice",
                "type": "object",
                "properties": [
                    {
                        "key": "merchant_name",
                        "description": "name of the merchant",
                        "example": "Galactic Solutions",
                        "type": "string"
                    },
                    {
                        "key": "merchant_address",
                        "description": "address of the merchant",
                        "example": "789 Elm Rd, Seattle, WA 98109",
                        "type": "string"
                    },
                    {
                        "key": "merchant_tax_id",
                        "description": "tax id or vat id of the merchant",
                        "example": "123987456",
                        "type": "string"
                    }
                ]
            },
            {
                "key": "items",
                "description": "the items in the receipt",
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": [
                        {
                            "key": "name",
                            "example": "Item 1",
                            "type": "string"
                        },
                        {
                            "key": "quantity",
                            "example": "1",
                            "type": "string"
                        },
                        {
                            "key": "unit_price",
                            "description": "return only the number as a string.",
                            "example": "100.00",
                            "type": "string"
                        },
                        {
                            "key": "total_price",
                            "description": "return only the number as a string.",
                            "example": "100.00",
                            "type": "string"
                        }
                    ]
                }
            },
            {
                "key": "total_tax_amount",
                "description": "The amount of tax charged on the invoice. This is the tax figure listed separately from the sub-total. Return only the number as a string.",
                "example": "163.97",
                "type": "string"
            },
            {
                "key": "grand_total",
                "description": "The total amount after tax has been added. This should capture the final payable amount. Return only the number as a string.",
                "example": "1027.00",
                "type": "string"
            }
        ]
    }
}
```

</details>

## Utilizing the Template

1. **Obtain an API Key**: First, ensure you have an API key by registering at [https://app.extracta.ai](https://app.extracta.ai/) and creating your key on the `/api` page.
2. **Execute the API Request**: Incorporate the JSON template in your `POST` request to `/createExtraction`, including your API key in the header for authentication.
3. **Integrate Extracted Data**: The API will process your receipt and return detailed, structured data, ready to be integrated into your financial systems or applications.

## Code Example

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

/**
 * Initiates a new document extraction process with the provided details.
 * 
 * @param {string} token - The authorization token for API access.
 * @param {Object} extractionDetails - The details of the extraction to be created.
 * @returns {Promise<Object>} The promise that resolves to the API response with the new extraction ID.
 */
async function createExtraction(token, extractionDetails) {
    const url = "https://api.extracta.ai/api/v1/createExtraction";

    try {
        const response = await axios.post(url, {
            extractionDetails
        }, {
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${token}`
            }
        });

        // Handling response
        return response.data; // Directly return the parsed JSON response
    } catch (error) {
        // Handling errors
        throw error.response ? error.response.data : new Error('An unknown error occurred');
    }
}

async function main() {
    const token = 'apiKey';
    const extractionDetails = {}; // the json body from the example

    try {
        const response = await createExtraction(token, extractionDetails);
        console.log("New Extraction Created:", response);
    } catch (error) {
        console.error("Failed to create new extraction:", error);
    }
}

main();
```

{% endtab %}

{% tab title="Python" %}

```python
import requests


def create_extraction(token, extraction_details):
    url = "https://api.extracta.ai/api/v1/createExtraction"
    headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}

    try:
        response = requests.post(url, json=extraction_details, headers=headers)
        response.raise_for_status()  # Raises an HTTPError if the response status code is 4XX/5XX
        return response.json()  # Returns the parsed JSON response
    except requests.RequestException as e:
        # Handles any requests-related errors
        print(e)
        return None


# Example usage
if __name__ == "__main__":
    token = "apiKey"
    extraction_details = {} # the json body from the example

    response = create_extraction(token, extraction_details)
    print("New Extraction Created:", response)
```

{% endtab %}
{% endtabs %}

## Leveraging Receipt Data

With Extracta LABS, you can unlock the potential of your receipt data, automating and refining financial processes with our advanced parsing technology. This not only saves time but also provides accurate, actionable insights from your transactional documents.

For more information on how to integrate Extracta LABS into your workflows, refer to our detailed  [api-endpoints-data-extraction](https://docs.extracta.ai/data-extraction-api/api-endpoints-data-extraction "mention") and [1.-create-extraction](https://docs.extracta.ai/data-extraction-api/api-endpoints-data-extraction/1.-create-extraction "mention") pages.
