/system/attachments
Path: /system/attachments
Namespace: system
Resource: attachments
Overview
The Attachment resource in the system namespace provides system administrators with access to file attachments across all domains for system-wide file management.
Key Difference from Admin: The system namespace provides cross-tenant access for system administrators, while the admin namespace is scoped to a single domain.
Relationships
Attachment connects to:
- Blob (
blob_id) - Associated blob storage - Attachable (polymorphic) - Can be associated with any resource
- Domain (
host_id) - Tenant domain
Key Features
- System-Wide Access: Access to all attachments across all tenants
- Cross-Tenant Management: Manage attachments from all tenants
- File Management: Upload, download, and manage file attachments
- Polymorphic Association: Attachments can be associated with any resource
Available Operations
List Attachments (GET)
Endpoint: GET /system/attachments.json
Query Parameters:
q[field_predicate]=value- Ransack query filters for advanced filteringpage=N- Page number for paginationper_page=N- Items per page (default: 25)
Request Examples:
curl -X GET "https://your-company.erpax.com/system/attachments.json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie"2
3
JavaScript Example:
const response = await fetch('/system/attachments.json', {
credentials: 'include',
headers: { 'Accept': 'application/json' }
});
const data = await response.json();2
3
4
5
Response (200 OK):
{
"attachments": [
{
"id": 1,
"filename": "document.pdf",
"content_type": "application/pdf",
"byte_size": 102400,
"blob_id": 1,
"attachable_type": "Invoice",
"attachable_id": 123,
"created_at": "2024-01-15T10:00:00Z"
}
],
"meta": {
"current_page": 1,
"per_page": 25,
"total_pages": 1,
"total_count": 5
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Show Attachment (GET /:id)
Endpoint: GET /system/attachments/:id.json
Request Example:
curl -X GET "https://your-company.erpax.com/system/attachments/1.json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie"2
3
Response (200 OK):
{
"attachment": {
"id": 1,
"filename": "document.pdf",
"content_type": "application/pdf",
"byte_size": 102400,
"blob_id": 1,
"attachable_type": "Invoice",
"attachable_id": 123,
"created_at": "2024-01-15T10:00:00Z"
}
}2
3
4
5
6
7
8
9
10
11
12
Create Attachment (POST)
Endpoint: POST /system/attachments.json
Request Example:
curl -X POST "https://your-company.erpax.com/system/attachments.json" \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/json" \
-H "Cookie: session_cookie" \
-F "attachment[file][email protected]" \
-F "attachment[attachable_type]=Invoice" \
-F "attachment[attachable_id]=123"2
3
4
5
6
7
Response (201 Created):
{
"attachment": {
"id": 2,
"filename": "document.pdf",
"content_type": "application/pdf",
"byte_size": 102400,
"blob_id": 2,
"created_at": "2024-01-15T14:30:00Z"
}
}2
3
4
5
6
7
8
9
10
Update Attachment (PATCH /:id)
Endpoint: PATCH /system/attachments/:id.json
Request Example:
curl -X PATCH "https://your-company.erpax.com/system/attachments/1.json" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie" \
-d '{
"attachment": {
"filename": "updated_document.pdf"
}
}'2
3
4
5
6
7
8
9
Response (200 OK):
{
"attachment": {
"id": 1,
"filename": "updated_document.pdf",
"updated_at": "2024-01-15T15:00:00Z"
}
}2
3
4
5
6
7
Delete Attachment (DELETE /:id)
Endpoint: DELETE /system/attachments/:id.json
Request Example:
curl -X DELETE "https://your-company.erpax.com/system/attachments/1.json" \
-H "Accept: application/json" \
-H "Cookie: session_cookie"2
3
Response (204 No Content):
(empty response)Scopes
No custom scopes are configured (uses default 'all' scope).
Filters
Available filters for searching and filtering attachments:
- filename_cont - Text filter - Search by filename (contains)
- content_type - Select filter - Filter by content type
- attachable_type - Select filter - Filter by attachable resource type
- attachable_id - Filter by attachable resource ID
- blob - Filter by blob
- created_at - Date filter - Filter by creation date
- updated_at - Date filter - Filter by update date
Business Rules
- System-Wide Access: System namespace provides access to all attachments across all tenants
- Cross-Tenant Management: System administrators can manage attachments across all tenants
- File Upload: Attachments support file upload via multipart/form-data
- Polymorphic Association: Attachments can be associated with any resource
Related Resources
- System Blobs - Blob storage management
- System Dashboard - System namespace overview