Skip to content

/client/messages

Path: /client/messages
Namespace: client
Resource: messages

Overview

The Message resource in the client namespace provides customers with access to messages and communications related to their account, orders, and support requests.

Relationships

Message connects to:

  • User (user_id) - User who sent/received the message
  • Domain (host_id) - Tenant domain
  • Messageable (polymorphic) - Can be associated with any resource (Order, Invoice, etc.)

Key Features

  • Customer Communication: Customers can send and receive messages
  • Order-Related Messages: Messages can be associated with orders
  • Support Requests: Messages can be used for support requests
  • Customer Self-Service: Customers can manage their own messages

Available Operations

List Messages (GET)

Endpoint: GET /client/messages.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/client/messages.json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie"

JavaScript Example:

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

Response (200 OK):

json
{
  "messages": [
    {
      "id": 1,
      "subject": "Order Status Inquiry",
      "body": "What is the status of my order?",
      "messageable_type": "Order",
      "messageable_id": 123,
      "user_id": 1,
      "created_at": "2024-01-15T10:00:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 25,
    "total_pages": 1,
    "total_count": 5
  }
}

Show Message (GET /:id)

Endpoint: GET /client/messages/:id.json

Request Example:

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

Response (200 OK):

json
{
  "message": {
    "id": 1,
    "subject": "Order Status Inquiry",
    "body": "What is the status of my order?",
    "messageable_type": "Order",
    "messageable_id": 123,
    "user_id": 1,
    "created_at": "2024-01-15T10:00:00Z",
    "updated_at": "2024-01-15T10:00:00Z"
  }
}

Create Message (POST)

Endpoint: POST /client/messages.json

Request Example:

bash
curl -X POST "https://your-company.erpax.com/client/messages.json" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie" \
  -d '{
    "message": {
      "subject": "Support Request",
      "body": "I need help with my order",
      "messageable_type": "Order",
      "messageable_id": 123
    }
  }'

JavaScript Example:

javascript
const response = await fetch('/client/messages.json', {
  method: 'POST',
  credentials: 'include',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  body: JSON.stringify({
    message: {
      subject: 'Support Request',
      body: 'I need help with my order',
      messageable_type: 'Order',
      messageable_id: 123
    }
  })
});
const message = await response.json();

Response (201 Created):

json
{
  "message": {
    "id": 2,
    "subject": "Support Request",
    "body": "I need help with my order",
    "messageable_type": "Order",
    "messageable_id": 123,
    "user_id": 1,
    "created_at": "2024-01-15T14:30:00Z"
  }
}

Update Message (PATCH /:id)

Endpoint: PATCH /client/messages/:id.json

Request Example:

bash
curl -X PATCH "https://your-company.erpax.com/client/messages/1.json" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Cookie: session_cookie" \
  -d '{
    "message": {
      "body": "Updated message text"
    }
  }'

Response (200 OK):

json
{
  "message": {
    "id": 1,
    "body": "Updated message text",
    "updated_at": "2024-01-15T15:00:00Z"
  }
}

Delete Message (DELETE /:id)

Endpoint: DELETE /client/messages/:id.json

Request Example:

bash
curl -X DELETE "https://your-company.erpax.com/client/messages/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 messages:

  • subject_cont - Text filter - Search by subject (contains)
  • body_cont - Text filter - Search by message body (contains)
  • messageable_type - Select filter - Filter by messageable resource type
  • messageable_id - Filter by messageable resource ID
  • created_at - Date filter - Filter by creation date
  • updated_at - Date filter - Filter by update date

Business Rules

  • Customer Self-Service: Customers can only access their own messages
  • Polymorphic Association: Messages can be associated with any resource
  • User Attribution: Messages are automatically attributed to the current user

Released under an open source license.