Quick Start
In this tutorial, we will show you step-by-step how to extract data from a document using the DocumentPro API.
#
Prerequisites- You need a DocumentPro account. If you haven't signed up yet, create an account here.
- Basic knowledge of making HTTP requests (we'll use Python in our examples).
- A document you want to parse (we'll use an invoice as an example).
#
Step 1: Get Your API KeyBefore you can make API calls, you need your API key.
- Log in to your DocumentPro account.
- Navigate to the API Keys section in your account settings.
- Copy your API key.
Important: Keep your API key secure and don't share it publicly.
#
Step 2: Upload a DocumentFirst, 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 DocumentNow 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.
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 ResultsFinally, 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.
#
ConclusionCongratulations! 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:
- Retrieved the API key from the DocumentPro dashboard.
- Uploaded a document using the
/v1/documents
endpoint. - Ran a parser on the uploaded document using the
/v1/documents/{document_id}/run_parser
endpoint. - Retrieved the parsed results using the
/files
endpoint.
#
What's Next?- Explore our API documentation for more detailed information on available endpoints and parameters.
- Learn how to create custom parsers for your specific document types.
- Check out our integration guides to see how you can incorporate DocumentPro into your existing workflows.