# GetSafeDocs API Documentation Welcome to the GetSafeDocs API! This documentation covers all available endpoints for secure document sharing, messaging, tracking, document requests, and more. --- ## Authentication The API uses session-based authentication. After successful login, a session is established and subsequent requests are authenticated automatically. ### Register - **Endpoint:** `POST /api/register.php` - **Body (JSON):** `{ "email": "user@example.com", "password": "yourpassword" }` - **Response:** `{ "success": true, "account_id": 123 }` or `{ "error": "..." }` ### Login - **Endpoint:** `POST /api/login.php` - **Body (JSON):** `{ "email": "user@example.com", "password": "yourpassword" }` - **Response:** `{ "success": true, "account_id": 123 }` or `{ "error": "..." }` - **Note:** Establishes a session for subsequent authenticated requests ### Logout - **Endpoint:** `POST /api/logout.php` - **Response:** `{ "success": true, "message": "Logged out successfully" }` ### Refresh Session - **Endpoint:** `POST /api/refresh_token.php` - **Response:** `{ "success": true, "account_id": 123 }` or `{ "error": "Not authenticated" }` --- ## Messages ### Send Message - **Endpoint:** `POST /api/send_message.php` - **Content-Type:** `application/x-www-form-urlencoded` - **Fields:** - `recipient` (string, required) - `subject` (string, required) - `body` (string, required) - `uploaded_file_ids` (string, optional) - Comma-separated list of file IDs from previous uploads - **Response:** `{ "success": true, "message_id": 123 }` or `{ "error": "..." }` - **Note:** Files must be uploaded separately using the file upload endpoints before sending the message ### List Sent Messages - **Endpoint:** `GET /api/list_messages.php?limit=20&offset=0` - **Response:** ``` { "success": true, "messages": [ { "message_id": 123, "subject": "Subject", "created_at": "...", "status": "sent", "recipients": "..." } ], "total": 42, "limit": 20, "offset": 0 } ``` ### List Received Messages - **Endpoint:** `GET /api/list_received_messages.php?limit=20&offset=0` - **Response:** ``` { "success": true, "messages": [ { "message_id": 456, "subject": "Subject", "created_at": "...", "status": "sent", "sender_email": "..." } ], "total": 42, "limit": 20, "offset": 0 } ``` ### View Message Details - **Endpoint:** `GET /api/message_details.php?message_id=123` - **Response:** ``` { "success": true, "message": { "message_id": 123, "subject": "...", "body": "...", "created_at": "...", "status": "...", "sender_email": "...", "recipients": ["..."], "attachments": [ { "file_id": 789, "file_name": "..." } ] } } ``` ### Delete Message - **Endpoint:** `POST /api/delete_message.php` - **Body (JSON):** `{ "message_id": 123 }` - **Response:** `{ "success": true }` or `{ "error": "..." }` --- ## Attachments ### Download Attachment - **Endpoint:** `GET /api/download_attachment.php?file_id=789` - **Response:** File download (if authorized) or JSON error --- ## File Uploads All file uploads now use a secure multi-step signed URL process for improved security and performance. This applies to both authenticated users and document request uploads. ### General File Upload Process #### Step 1: Get Signed Upload URL - **Endpoint:** `POST /get_signed_url.php` - **Authentication:** Required (for authenticated uploads) - **Content-Type:** `application/json` - **Body (JSON):** ``` { "filename": "document.pdf", "contentType": "application/pdf", "fileSize": 1024000 } ``` - **Response:** ``` { "success": true, "signedUrl": "https://storage.googleapis.com/bucket/temp/path?signature=...", "tempBucketPath": "user_uploads/uuid/document.pdf", "uuid": "12345678-1234-1234-1234-123456789012", "uploadToken": "base64encodedtoken" } ``` #### Step 2: Upload File to GCP - **Method:** `PUT` - **URL:** Use the `signedUrl` from Step 1 - **Content-Type:** Use the `contentType` from Step 1 - **Body:** Raw file data - **Response:** HTTP 200 on success #### Step 3: Process Upload - **Endpoint:** `POST /process_cloud_upload.php` - **Authentication:** Required (for authenticated uploads) - **Content-Type:** `application/json` - **Body (JSON):** ``` { "tempBucketPath": "user_uploads/uuid/document.pdf", "filename": "document.pdf", "contentType": "application/pdf", "fileSize": 1024000, "uuid": "12345678-1234-1234-1234-123456789012", "uploadToken": "base64encodedtoken" } ``` - **Response:** ``` { "success": true, "file_id": "temp_1234567890", "scan_result": { "rating": 0, "risk": "Clean", "access_uuid": "access_1234567890" } } ``` ### Upload File - **Endpoint:** `POST /api/upload_file.php` - **Authentication:** Required - **Content-Type:** `application/json` - **Body (JSON):** Same as Step 3 above - **Response:** Same as Step 3 above - **Note:** This endpoint combines all three steps for convenience, but still uses the signed URL process internally ### Get Document Request Signed URL - **Endpoint:** `POST /api/get_document_request_signed_url.php` - **Authentication:** Token-based (via `access_token` parameter) - **Purpose:** Get a signed URL for uploading files to a document request without requiring user authentication - **Content-Type:** `application/json` - **Body (JSON):** ``` { "filename": "document.pdf", "contentType": "application/pdf", "fileSize": 1024000, "access_token": "abc123def456" } ``` - **Response:** Same format as general signed URL endpoint - **Validations:** - Validates document request token is active and not expired - Enforces document request file size limits - Validates file types against allowed types (if specified) - Checks security restrictions (forbidden file types) - **Note:** This is a specialized version of `/get_signed_url.php` designed specifically for document request uploads with token-based authentication instead of session-based authentication ### Benefits of Signed URL Uploads - **Security:** Upload tokens prevent replay attacks and unauthorized uploads - **Performance:** Direct upload to GCP without going through the web server - **Scalability:** Reduces server load and bandwidth usage - **Reliability:** Better error handling and progress tracking - **Consistency:** All uploads follow the same secure pattern - **Token-based Access:** Document requests can accept uploads without requiring user accounts ### File Type Validation All file uploads are validated using centralized functions in `functions.php` to ensure consistency across all endpoints. **For current file type support, see:** [File Types Reference](/file_types.php) (HTML) | [JSON](/file_types.php?format=json) | [Markdown](/file_types.php?format=markdown) The system supports: - **Free Tier:** 60+ file types including documents, images, archives, and code files - **Premium/Enterprise:** All free tier types plus video, audio, and design files - **Forbidden:** Executable files and scripts blocked for security reasons across all tiers File type lists are maintained in `includes/functions.php` via these functions: - `getAllowedFileExtensions()` - Free tier supported types - `getPremiumFileExtensions()` - Premium-only additional types - `getForbiddenFileExtensions()` - Security-blocked types #### Validation Process: 1. **Client-side pre-validation** - File type checking before upload 2. **Server-side extension validation** - Forbidden extension check 3. **Tier-based restrictions** - User tier determines allowed types 4. **Content-Type validation** - MIME type verification 5. **Upload token validation** - Cryptographic token verification 6. **MIME type verification** - Post-upload content inspection 7. **Malware scanning** - QuickSand static analysis #### Error Responses: - **Forbidden file type:** `{ "success": false, "message": "File type 'exe' is not allowed for security reasons..." }` - **Unsupported for tier:** `{ "success": false, "message": "File type 'mp4' is not supported for free accounts..." }` - **MIME mismatch:** `{ "success": false, "message": "File content does not match the 'pdf' extension..." }` --- ### Message Tracking - **Endpoint:** `GET /api/message_tracking.php?message_id=123` - **Response:** ``` { "success": true, "message_id": 123, "subject": "...", "created_at": "...", "tracking": [ { "activity_type": "message_sent", "activity_timestamp": "...", "ip_address": "...", "user_agent": "...", "recipient_email": "..." } ] } ``` --- ## Replies ### Add Reply - **Endpoint:** `POST /api/add_reply.php` - **Body (JSON):** `{ "message_id": 123, "reply_text": "...", "parent_reply_id": 5 }` - **Response:** `{ "success": true, "reply_id": 42 }` or `{ "error": "..." }` ### List Replies - **Endpoint:** `GET /api/list_replies.php?message_id=123` - **Response:** ``` { "success": true, "replies": [ { "reply_id": 42, "message_id": 123, "recipient_id": 7, "reply_text": "...", "created_at": "...", "is_read": 0, "parent_reply_id": null, "is_sender_reply": 1, "viewed_at": null } ] } ``` ### Mark Reply as Read - **Endpoint:** `POST /api/mark_reply_read.php` - **Body (JSON):** `{ "reply_id": 42 }` - **Response:** `{ "success": true }` or `{ "success": true, "already_read": true }` --- ## Document Requests Document requests allow external users to upload files using a secure token without requiring an account. **Note:** The API field is called `access_token` in both the documentation and implementation. ### Create Document Request - **Endpoint:** `POST /api/create_document_request.php` - **Authentication:** Required (premium users only) - **Body (JSON):** ``` { "request_name": "Contract Documents", "description": "Please upload the signed contract and supporting documents", "allow_multiple_submissions": true, "max_file_size_mb": 50, "max_files_per_submission": 10, "allowed_file_types": "pdf,doc,docx", "require_email": true, "require_subject": false, "require_message": true, "expiry_days": 30 } ``` - **Response:** ``` { "success": true, "message": "Document request created successfully", "request": { "request_id": 123, "request_name": "Contract Documents", "description": "Please upload the signed contract and supporting documents", "access_token": "abc123def456", "allow_multiple_submissions": true, "max_file_size_mb": 50, "max_files_per_submission": 10, "allowed_file_types": "pdf,doc,docx", "require_email": true, "require_subject": false, "require_message": true, "expiry_date": "2024-02-15 10:30:00", "expiry_days": 30, "upload_url": "../document_request_upload.php?token=abc123def456", "created_at": "2024-01-16 10:30:00" } } ``` - **Error Responses:** - `{ "success": false, "message": "Not authenticated" }` (401) - `{ "success": false, "message": "Document request creation is a premium feature..." }` (403) - `{ "success": false, "message": "Request name is required" }` (400) - `{ "success": false, "message": "Maximum file size must be between 1 and X MB..." }` (400) ### Upload Document Request File **Note:** This endpoint now uses a multi-step signed URL upload process for improved security and performance. #### Step 1: Get Signed Upload URL (Document Requests) - **Endpoint:** `POST /api/get_document_request_signed_url.php` - **Authentication:** Not required (token-based via `access_token`) - **Content-Type:** `application/json` - **Body (JSON):** ``` { "filename": "document.pdf", "contentType": "application/pdf", "fileSize": 1024000, "access_token": "abc123def456" } ``` - **Response:** ``` { "success": true, "signedUrl": "https://storage.googleapis.com/bucket/temp/path?signature=...", "tempBucketPath": "document_requests/uuid/document.pdf", "uuid": "12345678-1234-1234-1234-123456789012", "uploadToken": "base64encodedtoken" } ``` - **Error Responses:** - `{ "success": false, "message": "Missing required parameters" }` (400) - `{ "success": false, "message": "Token is required" }` (400) - `{ "success": false, "message": "Invalid or inactive token" }` (400) - `{ "success": false, "message": "This document request has expired" }` (400) - `{ "success": false, "message": "File exceeds maximum size limit of X MB" }` (400) - `{ "success": false, "message": "File type not allowed for security reasons" }` (400) - `{ "success": false, "message": "File type 'ext' is not allowed. Allowed types: ..." }` (400) - `{ "success": false, "message": "File type does not match content" }` (400) #### Step 2: Upload File to GCP - **Method:** `PUT` - **URL:** Use the `signedUrl` from Step 1 - **Content-Type:** Use the `contentType` from Step 1 - **Body:** Raw file data - **Response:** HTTP 200 on success #### Step 3: Process Upload - **Endpoint:** `POST /api/upload_document_request_file.php` - **Content-Type:** `application/json` - **Body (JSON):** ``` { "tempBucketPath": "user_uploads/uuid/document.pdf", "filename": "document.pdf", "contentType": "application/pdf", "fileSize": 1024000, "uuid": "12345678-1234-1234-1234-123456789012", "uploadToken": "base64encodedtoken", "access_token": "abc123def456" } ``` - **Response:** ``` { "success": true, "file_id": "docreq_temp_1234567890", "message": "File uploaded and scanned successfully", "scan_result": { "rating": 0, "risk": "Clean", "uuid": "12345678-1234-1234-1234-123456789012", "access_uuid": "access_1234567890", "scan_id": 12345 } } ``` - **Error Responses:** - `{ "success": false, "message": "Missing required parameters" }` - `{ "success": false, "message": "Invalid upload token" }` - `{ "success": false, "message": "File not found in temp bucket" }` - `{ "success": false, "message": "File content does not match file type" }` - `{ "success": false, "message": "Invalid or inactive token" }` - `{ "success": false, "message": "This document request has expired" }` - `{ "success": false, "message": "File exceeds maximum size limit of X MB" }` - `{ "success": false, "message": "File type not allowed for security reasons" }` ### Get Submission Details - **Endpoint:** `GET /api/get_submission_details.php?submission_id=123` - **Authentication:** Required (account owner only) - **Response:** ``` { "success": true, "html": "