Upload Document
You can use the REST API to upload documents directly to DocumentPro. Once uploaded, documents can be sent to Workflow.
API Endpoint
POST https://api.documentpro.ai/v1/documents
Request
Headers
x-api-key
: Your API key for authentication.
Body
The request body should be multipart/form-data
with the following field:
file
: The document file you want to upload.
Example Implementation
Using cURL
curl --location 'https://api.documentpro.ai/v1/documents' \
--header 'x-api-key: YOUR_API_KEY' \
--form 'file=@"/path/to/your/document.pdf"'
Using Python
import requests
url = "https://api.documentpro.ai/v1/documents"
headers = {
'x-api-key': 'YOUR_API_KEY'
}
files = {
'file': ('document.pdf', open('/path/to/your/document.pdf', 'rb'), 'application/pdf')
}
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
result = response.json()
print(f"File uploaded successfully. Document ID: {result['document_id']}")
print(result)
else:
print('Failed to upload file')
print(response.text)
Response
Successful Response (Status Code: 200)
{
"document_id": "0b13c9f2-5148-4ffb-bb7b-de03bb071ca8",
"user_id": "4449b25a-9bba-4de4-be67-c06233d2f305",
"source_name": "api",
"file_name": "file_name.pdf",
"file_extension": "pdf",
"num_pages": 8,
"meta_tags": {},
"parser_runs": [],
"created_at": "2024-07-25T14:16:44.540197",
"updated_at": "2024-07-25T14:16:44.540223"
}
Error Response (Status Codes: 400, 403, 500)
{
"success": false,
"error": "error_code",
"message": "descriptive error message"
}
Important Notes
- The API can upload files up to 6MB in size.
- Supported file formats include PDF, JPEG, PNG, and TIFF.
- The
document_id
in the response is crucial for subsequent operations, such as sending the document to a Workflow. - Uploading a document does not automatically parse it. You need to send the document to a Workflow in a separate API call.
Next Steps
After successfully uploading a document:
- Send document to a Workflow on the uploaded document using its
document_id
. - Retrieve workflow results once the parsing is complete.
- List your documents to see all uploaded documents in your account.