Skip to main content

Quick Start

In this tutorial, we will show you step-by-step how to extract data from a document using the DocumentPro API.

Prerequisites#

  1. You need a DocumentPro account. If you haven't signed up yet, create an account here.
  2. Basic knowledge of making HTTP requests (we'll use Python in our examples).
  3. A document you want to parse (we'll use an invoice as an example).

Step 1: Get Your API Key#

Before you can make API calls, you need your API key.

  1. Log in to your DocumentPro account.
  2. Navigate to the API Keys section in your account settings.
  3. Copy your API key.

API Key Location

Important: Keep your API key secure and don't share it publicly.

Step 2: Upload a Document#

First, we'll upload a document to DocumentPro using the API.

import requests
url = "https://api.documentpro.ai/v1/documents"files = [  ('file', ('invoice.pdf', open('/path/to/your/invoice.pdf', 'rb'), 'application/pdf'))]headers = {  'x-api-key': 'YOUR_API_KEY_HERE'}
response = requests.post(url, headers=headers, files=files)print(response.text)

Replace 'YOUR_API_KEY_HERE' with your actual API key, and update the file path to point to your document.

This API call will return a response containing the document_id. Save this ID as you'll need it for the next step.

Step 3: Run a Parser on the Document#

Now that we've uploaded a document, we can run a parser on it. You'll need the template_id of the parser you want to use.

Template ID Location

Here's how to run the parser:

import requests
document_id = "YOUR_DOCUMENT_ID_HERE"template_id = "YOUR_TEMPLATE_ID_HERE"
url = f"https://api.documentpro.ai/v1/documents/{document_id}/run_parser"
headers = {  'x-api-key': 'YOUR_API_KEY_HERE',  'Accept': 'application/json'}
params = {    'template_id': template_id,    'use_ocr': True,    'query_model': 'gpt-4o',    'detect_layout': True,    'detect_tables': True,    'page_ranges': '1-3'}
response = requests.get(url, headers=headers, params=params)print(response.text)

Replace 'YOUR_DOCUMENT_ID_HERE', 'YOUR_TEMPLATE_ID_HERE', and 'YOUR_API_KEY_HERE' with your actual values.

This API call will return a request_id. Save this ID for the final step.

Step 4: Retrieve the Results#

Finally, we can retrieve the parsed results using the request_id from the previous step:

import requests
request_id = "YOUR_REQUEST_ID_HERE"
url = "https://api.documentpro.ai/files"
headers = {  'x-api-key': 'YOUR_API_KEY_HERE',  'Accept': 'application/json'}
params = {  'request_id': request_id}
response = requests.get(url, headers=headers, params=params)print(response.text)

Replace 'YOUR_REQUEST_ID_HERE' and 'YOUR_API_KEY_HERE' with your actual values.

This API call will return the parsed data from your document.

Conclusion#

Congratulations! You've successfully used the DocumentPro API to upload a document, run a parser on it, and retrieve the results.

Here's a quick recap of what we did:

  1. Retrieved the API key from the DocumentPro dashboard.
  2. Uploaded a document using the /v1/documents endpoint.
  3. Ran a parser on the uploaded document using the /v1/documents/{document_id}/run_parser endpoint.
  4. Retrieved the parsed results using the /files endpoint.

What's Next?#