Skip to main content

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 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#

  1. The API can upload files up to 6MB in size.
  2. Supported file formats include PDF, JPEG, PNG, and TIFF.
  3. The document_id in the response is crucial for subsequent operations, such as running a parser on the document.
  4. Uploading a document does not automatically parse it. You need to run a parser on the uploaded document in a separate API call.

Next Steps#

After successfully uploading a document:

  1. Run a parser on the uploaded document using its document_id.
  2. Retrieve parsing results once the parsing is complete.
  3. List your documents to see all uploaded documents in your account.