Upload Document
You can use the REST API to upload documents directly to DocumentPro. Once uploaded, documents are available for parsing using the parsers in your account.
#
API EndpointPOST https://api.documentpro.ai/v1/documents
#
Request#
Headersx-api-key
: Your API key for authentication.
#
BodyThe request body should be multipart/form-data
with the following field:
file
: The document file you want to upload.
#
Example Implementation#
Using cURLcurl --location 'https://api.documentpro.ai/v1/documents' \--header 'x-api-key: YOUR_API_KEY' \--form 'file=@"/path/to/your/document.pdf"'
#
Using Pythonimport 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 running a parser on the document. - Uploading a document does not automatically parse it. You need to run a parser on the uploaded document in a separate API call.
#
Next StepsAfter successfully uploading a document:
- Run a parser on the uploaded document using its
document_id
. - Retrieve parsing results once the parsing is complete.
- List your documents to see all uploaded documents in your account.