Quick Start using API
In this tutorial, we will show you step-by-step how to send documents to a DocumentPro using our Rest 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 send to the Workflow (we'll use an invoice as an example).
Step 1: Create a Workflow on DocumentPro
Initially you need to create a Workflow on DocumentPro web so that you can get access to your API Key. Once you have your Account API Key you can create additional Workflows using the Rest API.
- Log in to your DocumentPro account.
- Navigate to the https://app.documentpro.ai/new-workflow.
- Set your Workflow Name.
- In the Document Parsing section set the document type.
- Next, click on Configure Parser and add the fields you want to extract from your Document. Save Configurations.
- Click on Create Workflow. You will be redirected to your Workflow.
Step 1: Get Your API Key
Before you can make API calls, you need your API key.
- On your Workflow Page, click on the Import section in Workflow tab.
- You will see an API section with the ability to Create API Key. Click is to get a new API Key. This API key will be the same across all your Workflows.
- Copy your API key.
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: Send your Document to a Workflow
Now that we've uploaded a document, we can send it to the Workflow you created before. Note the workflow_id
in the Workflow tab of the Workflow page.
Here's how to send the document to the Workflow:
import requests
document_id = "YOUR_DOCUMENT_ID_HERE"
template_id = "YOUR_WORKFLOW_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, # Optional, defaults to Workflow setting
'query_model': 'gpt-4o', # Optional, defaults to Workflow setting
'detect_layout': True, # Optional, defaults to Workflow setting
'detect_tables': True, # Optional, defaults to Workflow setting
'page_ranges': '1-3' # Optional, defaults to Workflow setting
}
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:
- Created a Workflow on DocumentPro
- Retrieved the API key from the DocumentPro dashboard.
- Uploaded a document using the
/v1/documents
endpoint. - Sent the document to the Workflow 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 a workflow using the API.
- Check out our integration guides to see how you can incorporate DocumentPro into your existing workflows.