Document Management API Documentation

This API allows you to manage documents, including uploading, querying, and deleting them.

Base URL

All endpoints are relative to the base URL: http://127.0.0.1:5001

Endpoints

1. Add Document to Main Table

POST /documents

Uploads a new document to the main documents table.

Request Parameters:

Parameter Type Required Description
file File Required The document file (multipart/form-data)
property_id String Required Property identifier
uploaded_by String Required Must be either "buyer" or "seller"
document_tag String Required Type or category of document
buyer_id String Required if uploaded_by="buyer" Buyer identifier
seller_id String Required if uploaded_by="seller" Seller identifier

Response:

{
    "message": "Document added successfully",
    "document_id": 123
}
        

2. Add Document to Buyer Table

POST /documents/buyer

Uploads a new document to the buyer documents table (for documents not associated with a property).

Request Parameters:

Parameter Type Required Description
file File Required The document file (multipart/form-data)
buyer_id String Required Buyer identifier
document_tag String Required Type or category of document

Response:

{
    "message": "Document added successfully",
    "document_id": 123
}
        

3. Query Documents from Main Table

GET /documents/query

Retrieves documents from the main documents table based on optional filters.

Query Parameters:

Parameter Type Required Description
property_id String Optional Filter by property identifier
uploaded_by String Optional Filter by uploader type ("buyer" or "seller")
buyer_id String Optional Filter by buyer identifier
seller_id String Optional Filter by seller identifier
document_tag String Optional Filter by document type/category

Response:

{
    "count": 2,
    "documents": [
        {
            "document_id": 123,
            "filename": "contract.pdf",
            "file_type": "application/pdf",
            "image_url": "data:application/pdf;base64,JVBERi0xLjMKJcTl8uXrp...",
            "datetime_uploaded": "2023-05-15T14:30:45.123456",
            "property_id": "456",
            "buyer_id": "789",
            "seller_id": "101",
            "uploaded_by": "buyer",
            "document_tag": "contract"
        },
        {
            "document_id": 124,
            "filename": "deed.pdf",
            "file_type": "application/pdf",
            "image_url": "data:application/pdf;base64,JVBERi0xLjQKJcOkw7zD...",
            "datetime_uploaded": "2023-05-14T10:15:22.654321",
            "property_id": "456",
            "buyer_id": "789",
            "seller_id": "101",
            "uploaded_by": "seller",
            "document_tag": "deed"
        }
    ]
}
        

4. Query Documents from Buyer Table

GET /documents/query/buyer

Retrieves documents from the buyer documents table.

Query Parameters:

Parameter Type Required Description
buyer_id String Required Filter by buyer identifier
document_tag String Optional Filter by document type/category

Response:

{
    "count": 1,
    "documents": [
        {
            "document_id": 125,
            "filename": "id_verification.jpg",
            "file_type": "image/jpeg",
            "image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD...",
            "datetime_uploaded": "2023-05-16T09:45:12.987654",
            "buyer_id": "789",
            "document_tag": "identification"
        }
    ]
}
        

5. Delete Document from Main Table

DELETE /documents/delete

Deletes a document from the main documents table based on provided criteria.

Query Parameters:

Parameter Type Required Description
property_id String Required Property identifier
uploaded_by String Required Must be either "buyer" or "seller"
document_tag String Required Type or category of document
buyer_id String Required if uploaded_by="buyer" Buyer identifier
seller_id String Required if uploaded_by="seller" Seller identifier

Response:

{
    "message": "Document deleted successfully"
}
        

6. Delete Document from Buyer Table

DELETE /documents/buyer/delete

Deletes a document from the buyer documents table.

Query Parameters:

Parameter Type Required Description
buyer_id String Required Buyer identifier
document_tag String Required Type or category of document

Response:

{
    "message": "Document deleted successfully"
}
        

Example Usage

Adding a Document to Main Table

curl -X POST http://127.0.0.1:5001/documents \
    -F "file=@/path/to/document.pdf" \
    -F "property_id=456" \
    -F "buyer_id=789" \
    -F "uploaded_by=buyer" \
    -F "document_tag=contract"
    

Adding a Document to Buyer Table

curl -X POST http://127.0.0.1:5001/documents/buyer \
    -F "file=@/path/to/id.jpg" \
    -F "buyer_id=789" \
    -F "document_tag=identification"
    

Querying Documents from Main Table

curl "http://127.0.0.1:5001/documents/query?property_id=456&uploaded_by=buyer"
    

Querying Documents from Buyer Table

curl "http://127.0.0.1:5001/documents/query/buyer?buyer_id=789"
    

Deleting a Document from Main Table

curl -X DELETE "http://127.0.0.1:5001/documents/delete?property_id=456&uploaded_by=buyer&document_tag=contract&buyer_id=789"
    

Deleting a Document from Buyer Table

curl -X DELETE "http://127.0.0.1:5001/documents/buyer/delete?buyer_id=789&document_tag=identification"
    

Notes