Sending Notifications by Rules
Getting All Rules
GET api/mailings
Response:
json
{
"status": "ok",
"timestamp": 1684398090000,
"data": [
{
"id": 1,
"email_template_id": 28,
"sms_template_id": null,
"type": "operational",
"verified": true,
"rule": "newClient",
"send_at": "00:00:00",
"cron_schedule": null,
"daily": true,
"request": null,
"stop_on_weekend": false,
"client_type_flags": 7,
"processed_at": "2023-05-17",
"created_at": null,
"updated_at": "2023-05-17 09:09:52",
"deleted_at": null,
"expression": null
}
]
}Getting a Rule by ID
GET api/mailings/{mailingID}
Creating a Rule
POST api/mailings
Request body: mailing
Updating a Rule
PUT api/mailings/{mailingId}
Request body: mailing
Deleting a Rule
DELETE api/mailings/{mailingId}
Mailing Object
| Field | Required | Type | Description |
|---|---|---|---|
| sms_template_id | If email_template_id is not specified | int | SMS message ID |
| email_template_id | If sms_template_id is not specified | int | Email message ID |
| type | ✅ | enum(operational,marketing) | Message type |
| rule | ✅ | string | Notification sending rule |
| send_at | ✅ | time(H:i:s) | Time for sending daily notifications |
| cron_schedule | ❌ | string | Cron expression for sending custom notifications. Works only with the custom rule |
| daily | ✅ | boolean | Daily notifications flag |
| request | ❌ | object | Object for retrieving entities for sending custom notifications |
| stop_on_weekend | ✅ | boolean | Flag to disable notifications on weekends |
| expression | ❌ | string | Expression for additional rule validation |
Custom Notifications
To send such notifications, you need to use the cron and request fields
Let's consider an example of sending a notification on March 8th to all women with active contracts. daily=false
cron="* * 8 3 *" - This entry ensures that this rule is processed only on the 8th day of the 3rd month
json
{
"request": {
"url": "main/contracts/partial-load",
"body": {
"fields": ["client.id", "client.mobilePhone", "client.email"],
"orderBy": "id",
"countFrom": 0,
"searchFields": [
{
"field": "issueDate",
"value": "not null"
},
{
"field": "closeDate",
"value": "null"
},
{
"field": "client.sex.id",
"value": "101252"
}
],
"orderByFields": [],
"orderDirection": "DESC"
},
"emailKey": "client.email",
"phoneKey": "client.mobilePhone",
"clientIdKey": "client.id"
}
}where,
url- Core address to request for data retrievalbody- Request body for retrieving all entities for sendingemailKey- Path to the client's email field after executing a POST request tourlwith thebodyphoneKey- Path to the client's phone fieldclientIdKey- Path to the client's identifier field