Skip to content

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

FieldRequiredTypeDescription
sms_template_idIf email_template_id is not specifiedintSMS message ID
email_template_idIf sms_template_id is not specifiedintEmail message ID
typeenum(operational,marketing)Message type
rulestringNotification sending rule
send_attime(H:i:s)Time for sending daily notifications
cron_schedulestringCron expression for sending custom notifications. Works only with the custom rule
dailybooleanDaily notifications flag
requestobjectObject for retrieving entities for sending custom notifications
stop_on_weekendbooleanFlag to disable notifications on weekends
expressionstringExpression 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 retrieval
  • body - Request body for retrieving all entities for sending
  • emailKey - Path to the client's email field after executing a POST request to url with the body
  • phoneKey - Path to the client's phone field
  • clientIdKey - Path to the client's identifier field