> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.wiraya.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Enqueue Communications API Documentation

## 📘 Overview

The `EnqueueCommunications` API allows you to queue messages for delivery. It’s used to schedule communications with recipient information and message content, which the system will later process and send.

---

## 🔗 Endpoint

* **URL:** `https://api.wiraya.com/api/EnqueueCommunications`
* **Method:** `POST`

**Accepted Content Types (Request):**

* `application/json`
* `text/json`
* `application/xml`
* `text/xml`
* `application/x-www-form-urlencoded`

**Supported Response Formats:**

* `application/json`
* `text/json`
* `application/xml`
* `text/xml`

---

## 🔐 Authentication

This API requires an API key, passed in the request header:

```
X-ApiKey: your_api_key_here
```

---

## 📥 Request Format

```
{  
  "communications": [  
    {  
      "clientMessageId": "string",  
      "recipient": "string",  
      "content": {  
        "$type": "string"  
      }  
    }  
  ]  
}
```

## 📌 Request Fields

| Field | Type | Required | Description |
| ---- |
| communications | Array | Yes | List of messages to be enqueued |
| clientMessageId | String | Yes | Unique message ID provided by the client |
| recipient | String | Yes | The recipient’s contact details |
| content | Object | Yes | The content of the message. The $type field is mandatory |

---

## ✉️ Content Types ($type)

Each communication must define its type using the `$type` field. Required fields vary by type:

| $type Value | Required Fields | Optional Fields |
| ---- |
| VoiceProject | projectId (integer), placeholders (array of strings) | nextAttemptUtc (iso format date string in UTC) |
| SMSProject | projectId, placeholders | nextAttemptUtc (iso format date string in UTC) |
| WhatsappProject | projectId, placeholders | nextAttemptUtc (iso format date string in UTC) |
| SMSFromAlpha | sender (max 11 characters), text (string) | – |

---

## ✅ Response

```
{  
  "results": {  
    "clientMessageId1": {  
      "trackingId": "32-character-hexadecimal-string",  
      "success": true,  
      "isTransientError": false  
    }  
  }  
}
```

| Field | Type | Description |
| ---- |
| trackingId | String | Unique 32-character ID for the enqueued message |
| success | Boolean | Indicates whether the request succeeded |
| isTransientError | Boolean | Present only if success is false. true means retry is possible; false means permanent failure |

---

## 🧠 Template Content Requirements

For `SMSProject` and `WhatsappProject`:

* Content (excluding placeholders) must match a **pre-approved template**.
* Placeholders should only be used for dynamic values (e.g., name, appointment time).
* This ensures compliance with template-based messaging rules on external platforms.

---

## 📎 Example Requests & Responses

## VoiceProject

**Request:**

```
{  
  "communications": [  
    {  
      "clientMessageId": "12345",  
      "recipient": "46701234567",  
      "content": {  
        "$type": "VoiceProject",  
        "projectId": 123,  
        "placeholders": ["John", "Order #5678"]  
      }  
    }  
  ]  
}
```

**Response:**

```
{  
  "results": {  
    "12345": {  
      "trackingId": "abcdef1234567890abcdef1234567890",  
      "success": true,  
      "isTransientError": false  
    }  
  }  
}
```

---

## SMSProject

**Request:**

```
{  
  "communications": [  
    {  
      "clientMessageId": "12345",  
      "recipient": "46701234567",  
      "content": {  
        "$type": "SMSProject",  
        "projectId": 123,  
        "placeholders": ["John", "Order #5678"]  
      }  
    }  
  ]  
}
```

---

## WhatsappProject

**Request:**

```
{  
  "communications": [  
    {  
      "clientMessageId": "67890",  
      "recipient": "46709876543",  
      "content": {  
        "$type": "WhatsappProject",  
        "projectId": 789,  
        "placeholders": ["Jane", "Delivery on Monday"]  
      }  
    }  
  ]  
}
```

---

## SMSFromAlpha

**Request:**

```
{  
  "communications": [  
    {  
      "clientMessageId": "54321",  
      "recipient": "46705678901",  
      "content": {  
        "$type": "SMSFromAlpha",  
        "sender": "Wiraya",  
        "text": "Your verification code is 123456"  
      }  
    }  
  ]  
}
```

---

## 🚨 Error Handling

| HTTP Status Code | Error Message | Description |
| ---- |
| 400 | Invalid input format | Malformed or missing fields in request |
| 401 | Invalid API Key | Missing or incorrect API key |
| 500 | Server error | Unexpected server-side error |

---

## 📝 Notes

* `clientMessageId` must be **unique per request** to avoid duplicate sends.
* When `isTransientError = true`, retrying the same request may succeed.
* The `$type` field is mandatory and defines how the `content` is interpreted.
* The `sender` field for `SMSFromAlpha` must be max **11 characters**.