Complete API Documentation for Invoice Management System
Create a new user account
Request Body (JSON):
| Parameter | Type | Description |
|---|---|---|
| user_name | string | Username required |
| user_password | string | Password required |
| mobile_no | string | Mobile number (max 13 chars) optional |
Example Request:
{
"user_name": "john_doe",
"user_password": "securepass123",
"mobile_no": "9876543210"
}
Success Response (201):
{
"message": "User created successfully",
"user_id": 1
}
Error Responses:
400: {"error": "user_name and user_password are required"}
400: {"error": "User already exists"}
Authenticate user and login
Request Body (JSON):
| Parameter | Type | Description |
|---|---|---|
| user_name | string | Username required |
| user_password | string | Password required |
Example Request:
{
"user_name": "john_doe",
"user_password": "securepass123"
}
Success Response (200):
{
"message": "Login successful",
"user_id": 1,
"user_name": "john_doe"
}
Error Responses:
400: {"error": "user_name and user_password are required"}
401: {"error": "Invalid credentials"}
Upload a new invoice PDF document with optional metadata and supporting documents
Request Body (multipart/form-data):
| Parameter | Type | Description |
|---|---|---|
| user_id | string | User ID (also accepts auth_id) required |
| file | file | Main invoice PDF file required |
| vendor_name | string | Name of the vendor/supplier (max 30 chars) optional |
| vendor_tax_id | string | Vendor's tax identification number (max 30 chars) optional |
| invoice_no | string | Invoice number/reference (max 30 chars) optional |
| invoice_date | string | Invoice date (YYYY-MM-DD or DD-MM-YYYY format) optional |
| amt | number | Invoice amount optional |
| supporting_doc_1 | file | First supporting document (any file type) optional |
| supporting_doc_2 | file | Second supporting document (any file type) optional |
| remarks | string | Additional notes or remarks optional |
Example (curl):
curl -X POST http://localhost:8000/upload/ \ -F "user_id=123" \ -F "file=@/path/to/invoice.pdf" \ -F "vendor_name=ABC Corp" \ -F "vendor_tax_id=TAX123456" \ -F "invoice_no=INV-2024-001" \ -F "invoice_date=2024-12-10" \ -F "amt=1500.50" \ -F "supporting_doc_1=@/path/to/contract.pdf" \ -F "remarks=Q4 payment"
Success Response (201):
{
"message": "Invoice uploaded successfully",
"invoice_id": 1,
"file_path": "docs/123/invoice.pdf",
"supporting_doc_1": "docs/123/support1_contract.pdf",
"supporting_doc_2": null
}
Error Responses:
400: {"error": "user_id is required"}
400: {"error": "No file uploaded"}
400: {"error": "Only PDF files are allowed"}
Get all invoices for a specific user
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| user_id | string | User ID required |
Example Request:
GET /invoices/?user_id=123
Success Response (200):
{
"invoices": [
{
"id": 1,
"auth_id": "123",
"file_name": "docs/123/invoice.pdf",
"vendor_name": "ABC Corp",
"vendor_tax_id": "TAX123456",
"invoice_no": "INV-2024-001",
"invoice_date": "2024-12-10",
"amt": 1500.50,
"supporting_doc_1": null,
"supporting_doc_2": null,
"remarks": null,
"data_fetch": "Y"
}
]
}
Download the invoice PDF file
URL Parameters:
| Parameter | Type | Description |
|---|---|---|
| invoice_id | integer | Invoice ID required |
Example Request:
GET /invoice/1/file/
Success Response:
Returns the PDF file with Content-Type: application/pdf
Error Responses:
404: {"error": "Invoice not found"}
404: {"error": "File not found on server"}
Get invoice details with AI-extracted data
URL Parameters:
| Parameter | Type | Description |
|---|---|---|
| invoice_id | integer | Invoice ID required |
Example Request:
GET /invoice/1/data/
Success Response (200):
{
"invoice": {
"id": 1,
"auth_id": "123",
"file_name": "docs/123/invoice.pdf",
"vendor_name": "ABC Corp",
"vendor_tax_id": "TAX123456",
"invoice_no": "INV-2024-001",
"invoice_date": "2024-12-10",
"amt": 1500.50,
"data_fetch": "Y"
},
"invoice_data": {
"id": 1,
"status": "OK",
"data": {
"status": true,
"data": {
"language": "English",
"vendor_name": "ABC Corp",
"invoice_number": "INV-2024-001",
"total_amt": 1500.50,
"items": [...]
}
},
"manual_verified": "N",
"modified_by": "2024-12-10T10:30:00",
"refetch": "N",
"remarks": null
}
}
Mark an invoice for reprocessing by AI
URL Parameters:
| Parameter | Type | Description |
|---|---|---|
| invoice_id | integer | Invoice ID required |
Example Request:
POST /invoice/1/refetch/
Success Response (200):
{
"message": "Invoice marked for refetching",
"invoice_id": 1
}
Process a specific invoice using AI extraction. Only the user who uploaded the invoice can process it.
Request Body (JSON or form-data):
| Field | Type | Description |
|---|---|---|
| invoice_id | integer | The ID of the invoice to process required |
| user_id | string | User ID who uploaded the invoice required |
Only the user who uploaded the invoice (matching auth_id) can trigger processing.
Returns 403 Forbidden if user doesn't have permission.
Example Request:
POST /process-invoices/
Content-Type: application/json
{
"invoice_id": 123,
"user_id": "1"
}
Success Response (200):
{
"message": "Invoice processed successfully",
"invoice_id": 123,
"result": {
"invoice_id": 123,
"status": "success",
"message": "Processed successfully"
}
}
Already Processed Response (200):
{
"message": "Invoice already processed",
"invoice_id": 123,
"status": "already_processed"
}
Error Responses:
400: {"error": "invoice_id is required"}
400: {"error": "user_id is required"}
400: {"error": "invoice_id must be a valid integer"}
403: {"error": "Permission denied. You can only process invoices you uploaded."}
404: {"error": "Invoice not found"}
500: {"error": "Processing failed", "invoice_id": 123, "result": {...}}
Upload a PDF and extract invoice data using AI. Saves to invoice_direct_data table.
Request Body (multipart/form-data):
| Field | Type | Description |
|---|---|---|
| file | file | PDF file to process required |
Files are saved to: /direct_pdf/{client_ipv4}/{filename}.pdf
The client's IPv4 address is used to organize uploaded files.
Example Request:
POST /invoice/extract-data/ Content-Type: multipart/form-data file: invoice.pdf
Success Response (201):
{
"id": 1,
"filename": "direct_pdf/192_168_1_100/invoice.pdf",
"data": {
"status": true,
"message": "PDF processed successfully using raw PDF upload",
"model": "gemini-2.5-pro",
"data": {
"language": "English",
"type": "computerized",
"vendor_name": "ABC Corp",
"invoice_number": "INV-2024-001",
"total_amt": 1500.50,
"confidence": {...},
"items": [...]
}
},
"status": "OK"
}
Error Responses:
400: {"error": "No file uploaded"}
400: {"error": "Only PDF files are allowed"}
Retrieve extracted data by ID from invoice_direct_data table
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| id | integer | Record ID required |
Example Request:
GET /invoice/extract-data/get/?id=1
Success Response (200):
{
"id": 1,
"data": {
"status": true,
"message": "PDF processed successfully using raw PDF upload",
"model": "gemini-2.5-pro",
"data": {
"language": "English",
"type": "computerized",
"vendor_name": "ABC Corp",
"invoice_number": "INV-2024-001",
"total_amt": 1500.50,
"confidence": {...},
"items": [...]
}
},
"status": "OK",
"pdf_data": "base64_encoded_pdf_content..."
}
Error Responses:
400: {"error": "id is required"}
404: {"error": "Record not found"}
Download the PDF file for a given invoice_direct_data record
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| id | integer | Record ID required |
Example Request:
GET /invoice/extract-data/file/?id=1
Success Response:
Returns the PDF file with Content-Type: application/pdf
Error Responses:
400: {"error": "id is required"}
404: {"error": "Record not found"}
404: {"error": "File not found on server"}
Interactive verification UI - displays PDF on one side and extracted data on the other
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
| id | integer | Record ID from invoice_direct_data table required |
Example Usage:
Open in browser: /check/?id=1
This endpoint returns an interactive HTML page with:
Process PDF using Google Gemini AI with usage tracking, pricing calculation, and database logging
Request Body (JSON):
| Parameter | Type | Description |
|---|---|---|
| api_key | string | API key for authentication required |
| model | string | Gemini model name required |
| pdf_base64 | string | Base64 encoded PDF content required |
| pdf_name | string | Original PDF filename optional |
gemini-2.5-pro - Input: $1.25/1M tokens, Output: $10.00/1M tokensgemini-3-pro-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-3-pro-image-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-2.0-flash - Input: $0.10/1M tokens, Output: $0.40/1M tokens๐ฐ Prices saved to database are converted to INR at 1 USD = 90 INR
Example Request:
{
"api_key": "your_api_key",
"model": "gemini-2.5-flash",
"pdf_base64": "JVBERi0xLjQK...",
"pdf_name": "invoice.pdf"
}
Success Response (200):
{
"status": true,
"message": "PDF processed successfully",
"model": "gemini-2.5-flash",
"token_usage": {
"input_tokens": 1234,
"output_tokens": 567,
"total_tokens": 1801
},
"price": 0.00456,
"time_taken": 3.45,
"log_id": 123,
"data": {
"language": "English",
"type": "computerized",
"vendor_name": "ABC Corp",
"invoice_number": "INV-2024-001",
"total_amt": 1500.50,
"items": [...]
}
}
Each API call is logged to the invoice_time table with:
Error Responses:
400: {"error": "api_key is required"}
400: {"error": "model is required"}
400: {"error": "pdf_base64 is required"}
400: {"error": "Invalid model. Supported models: ..."}
401: {"error": "Invalid API key"}
Process PDF using Google Vertex AI with usage tracking, pricing calculation, and database logging
Request Body (JSON):
| Parameter | Type | Description |
|---|---|---|
| api_key | string | API key for authentication required |
| model | string | Gemini model name required |
| pdf_base64 | string | Base64 encoded PDF content required |
| pdf_name | string | Original PDF filename optional |
| project_id | string | Vertex AI project ID optional |
| location | string | Vertex AI location (default: us-central1) optional |
gemini-2.5-pro - Input: $1.25/1M tokens, Output: $10.00/1M tokensgemini-2.5-flash - Input: $0.10/1M tokens, Output: $0.40/1M tokensgemini-3-pro-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-3-pro-image-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokens๐ฐ Prices saved to database are converted to INR at 1 USD = 90 INR
Example Request:
{
"api_key": "your_api_key",
"model": "gemini-2.5-flash",
"pdf_base64": "JVBERi0xLjQK...",
"pdf_name": "invoice.pdf",
"project_id": "my-project",
"location": "us-central1"
}
Success Response (200):
{
"status": true,
"message": "PDF processed successfully via Vertex AI",
"model": "gemini-2.5-flash",
"token_usage": {
"input_tokens": 1234,
"output_tokens": 567,
"total_tokens": 1801
},
"price": 0.41,
"time_taken": 3.45,
"log_id": 123,
"data": {
"language": "English",
"type": "computerized",
"vendor_name": "ABC Corp",
"invoice_number": "INV-2024-001",
"total_amt": 1500.50,
"items": [...]
}
}
Error Responses:
400: {"error": "api_key is required"}
400: {"error": "model is required"}
400: {"error": "pdf_base64 is required"}
400: {"error": "Invalid model. Supported models: ..."}
401: {"error": "Invalid API key"}
Process PDF using Google AI Studio (Gemini) with reduced token usage - optimized prompt and generation config
Request Body (JSON):
| Parameter | Type | Description |
|---|---|---|
| api_key | string | API key for authentication required |
| model | string | Gemini model name required |
| pdf_base64 | string | Base64 encoded PDF content required |
| pdf_name | string | Original PDF filename optional |
gemini-2.5-pro - Input: $1.25/1M tokens, Output: $10.00/1M tokensgemini-3-pro-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-3-pro-image-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-2.5-flash - Input: $0.30/1M tokens, Output: $2.50/1M tokens๐ฐ Prices saved to database are converted to INR at 1 USD = 90 INR
Example Request:
{
"api_key": "your_api_key",
"model": "gemini-2.5-flash",
"pdf_base64": "JVBERi0xLjQK...",
"pdf_name": "invoice.pdf"
}
Success Response (200):
{
"status": true,
"message": "PDF processed (V2 optimized)",
"model": "gemini-2.5-flash",
"token_usage": {"input": 850, "output": 450, "total": 1300},
"price": 0.00285,
"time_taken": 2.8,
"log_id": 456,
"data": {...}
}
Process PDF using Google Vertex AI with reduced token usage - optimized prompt and generation config
Request Body (JSON):
| Parameter | Type | Description |
|---|---|---|
| api_key | string | API key for authentication required |
| model | string | Gemini model name required |
| pdf_base64 | string | Base64 encoded PDF content required |
| pdf_name | string | Original PDF filename optional |
| project_id | string | Google Cloud Project ID optional, uses default |
| location | string | Vertex AI region (e.g., asia-south1) optional |
gemini-2.5-pro - Input: $1.25/1M tokens, Output: $10.00/1M tokensgemini-3-pro-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-3-pro-image-preview - Input: $2.00/1M tokens, Output: $12.00/1M tokensgemini-2.5-flash - Input: $0.30/1M tokens, Output: $2.50/1M tokens๐ฐ Prices saved to database are converted to INR at 1 USD = 90 INR
Example Request:
{
"api_key": "your_api_key",
"model": "gemini-2.5-flash",
"pdf_base64": "JVBERi0xLjQK...",
"pdf_name": "invoice.pdf",
"project_id": "my-gcp-project",
"location": "asia-south1"
}
Success Response (200):
{
"status": true,
"message": "PDF processed via Vertex AI (V2 optimized)",
"model": "gemini-2.5-flash",
"token_usage": {"input": 850, "output": 450, "total": 1300},
"price": 0.00195,
"time_taken": 2.5,
"log_id": 789,
"data": {...}
}
Error Responses:
400: {"error": "api_key is required"}
400: {"error": "model is required"}
400: {"error": "pdf_base64 is required"}
400: {"error": "Invalid model. Supported models: ..."}
401: {"error": "Invalid API key"}
Receive webhook requests for all HTTP methods (GET, POST, PUT, DELETE) and log them to webhook_logs.json
Request Body (JSON, optional for POST/PUT):
{
"event": "payment.success",
"data": {
"amount": 100,
"currency": "INR"
}
}
Success Response (200):
{
"status": "success",
"message": "Webhook received and logged",
"timestamp": "2024-12-14T22:15:30.123456",
"method": "POST"
}
All webhook requests are stored in webhook_logs.json with the following format:
{
"2024-12-14T22:15:30.123456": {
"method": "POST",
"data": {...},
"query_params": null,
"headers": {...},
"content_type": "application/json",
"client_ip": "127.0.0.1"
}
}
Display all logged webhooks from webhook_logs.json, sorted by timestamp (newest first)
Example Request:
GET /webhook/show/
Success Response (200):
{
"total_webhooks": 3,
"logs": {
"2024-12-14T22:15:30.123456": {
"method": "POST",
"data": {"event": "payment.success", "amount": 100},
"query_params": null,
"headers": {...},
"content_type": "application/json",
"client_ip": "127.0.0.1"
},
...
}
}