Skip to content

/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 filtering
  • page=N - Page number for pagination
  • per_page=N - Items per page (default: 25)

Request Examples:

bash
curl -X GET "https://your-company.erpax.com/system/attachments.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

JavaScript Example:

javascript
const response = await fetch('/system/attachments.json', {
  credentials: 'include',
  headers: { 'Accept': 'application/json' }
});
const data = await response.json();

Response (200 OK):

json
{
  "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
  }
}

Show Attachment (GET /:id)

Endpoint: GET /system/attachments/:id.json

Request Example:

bash
curl -X GET "https://your-company.erpax.com/system/attachments/1.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

Response (200 OK):

json
{
  "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"
  }
}

Create Attachment (POST)

Endpoint: POST /system/attachments.json

Request Example:

bash
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"

Response (201 Created):

json
{
  "attachment": {
    "id": 2,
    "filename": "document.pdf",
    "content_type": "application/pdf",
    "byte_size": 102400,
    "blob_id": 2,
    "created_at": "2024-01-15T14:30:00Z"
  }
}

Update Attachment (PATCH /:id)

Endpoint: PATCH /system/attachments/:id.json

Request Example:

bash
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"
    }
  }'

Response (200 OK):

json
{
  "attachment": {
    "id": 1,
    "filename": "updated_document.pdf",
    "updated_at": "2024-01-15T15:00:00Z"
  }
}

Delete Attachment (DELETE /:id)

Endpoint: DELETE /system/attachments/:id.json

Request Example:

bash
curl -X DELETE "https://your-company.erpax.com/system/attachments/1.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

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

Released under an open source license.