Skip to content

Create an automation rule

POST
/openapi/messagerule
curl --request POST \
--url https://open-api.replyco.com/openapi/messagerule \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json-patch+json' \
--data '{ "ruleName": "Mark support reports read", "condition": { "tableName": "Thread", "fieldName": "Subject", "value1": "product support report" }, "action": { "tableName": "Message", "fieldName": "Unread", "value": "false" } }'

Creates an automation rule. Every incoming message is checked against the rule’s condition; when it matches, the action is applied to that message’s thread. Rules run in priority order (lowest number first).

A rule created here has exactly one condition and one action. For AND/OR groups of conditions or several actions, build the rule in the rule editor of the Replyco app; such rules are still listed here by their first condition and first action.

Request body

{
  "ruleName": "Auto-mark read: Amazon support reports",
  "priority": 0,
  "inActive": false,
  "condition": {
    "tableName": "Thread",
    "fieldName": "Subject",
    "operator": "Contain",
    "value1": "Amazon product support report available",
    "value2": null,
    "relations": null
  },
  "action": {
    "tableName": "Message",
    "fieldName": "Unread",
    "value": "false",
    "actionType": "UpdateField",
    "relations": null
  }
}
        
  • ruleName — required. Shown in the app and in each thread’s change log.
  • priority — optional. 0 places the rule after all existing rules; otherwise lower numbers run first.
  • inActive — optional. true creates the rule disabled.
  • condition.tableName / condition.fieldName — required. Which table and column to read (case-sensitive).
  • condition.operator — how to compare; name or number, see below. Defaults to Contain.
  • condition.value1 — required. What to compare with, always a string. condition.value2 — the upper bound for Between.
  • action.tableName — required. action.fieldName — the column to set; required for UpdateField.
  • action.value — required. The new value as a string, or a JSON object for InsertRelation.
  • action.actionType — UpdateField (0) or InsertRelation (2); name or number. Defaults to UpdateField.
  • relations — optional on both. The navigation path from Message to tableName; it is filled in automatically for every table listed below, so you can leave it out.

Operators (condition.operator)

  • Contain (0) — value1 appears anywhere in the field. Text only.
  • NotContain (1) — value1 does not appear; also true when the field is empty. Text only.
  • StartWith (2) / EndWith (3) — the field starts / ends with value1. Text only.
  • Equals (4) — exact match. Any type.
  • Between (5) — value1 ≤ field ≤ value2. Numbers and dates.

How to write value1 / value2 per field type

  • Text — the fragment or exact text, e.g. "refund".
  • Numbers (OrderTotalAmount, NumberOfMessages) — "100". Between needs both value1 and value2.
  • Dates (CreatedDate, LastUpdated, PurchaseDate, LatestShipDate, MessageDate) — use Between. Each bound is either a number of days ago ("7" = 7 days ago; must be 0 or greater) or an ISO date ("2026-01-31"). value1 is the older bound and value2 the newer one; leave value2 out to mean “up to now”.
    • created within the last 7 days: value1 "7"
    • created between 30 and 7 days ago: value1 "30", value2 "7"
    • not updated for 30 days: value1 "2000-01-01", value2 "30"
  • Yes/no (InActive, IsFromCompany, IsBlocked, Paid) — Equals with "true" or "false".
  • Statuses and marketplaces — Equals with the number. Thread Status: Open 0, InProgress 1, ActionRequired 2, Resolved 3, AwaitingCustomer 4, Snoozed 5. Marketplace: Ebay 1, Etsy 2, Mail 3, BigCommerce 4, WooCommerce 5, Magento 6, Shopify 7, Linnworks 8, Gmail 10, AmazonSP 16, Outlook 21 — the same numbers as marketplace in thread and account responses.
  • Ids (AccountId, PriorityId, UserId) — Equals with the GUID.

Conditions — what you can test

  • Message — the incoming message: Text (body), Title (the message’s own subject line), To, SenderAddress, LanguageCode (e.g. en), AccountId (the connected account it arrived on), MessageDate, IsFromCompany. Computed: NumberOfMessages — how many messages the thread has (Equals / Between).
  • Thread — the ticket: Subject, Status, Marketplace, CreatedDate, LastUpdated, InActive (archived), PriorityId, SalesChannel. Computed: DayOfWeek — Equals with a JSON array of weekdays in value1, 0 = Sunday … 6 = Saturday, e.g. "[0,6]" for weekends.
  • Customer — CustomerName, FirstName, LastName, Email, Phone, Marketplace, LanguageCode, IsBlocked.
  • Order — the order linked to the thread: Status (text, e.g. Shipped), PaymentStatus (text), MarketOrderId, OrderTotalAmount, PurchaseDate, LatestShipDate, TrackingNumber, ShippingService, PaymentMethod, ShopName, Paid.
  • Task — the assignment: UserId (assigned user; ids from GET /openApi/user/id_name).
  • Product — products of the linked order or thread: Title, MarketItemId, Category, SKU (text operators).

Other columns of these tables are accepted too, as long as value1 converts to the column’s type.

Actions — what you can do

  • Set thread status — Thread / Status / "3" (numbers as above). The inbox list is updated as well.
  • Archive / unarchive — Thread / InActive / "true" or "false".
  • Set SLA priority — Thread / PriorityId / "{priorityId}" (the priorityId shown on thread responses).
  • Assign to a user — Task / UserId / "{userId}" (ids from GET /openApi/user/id_name).
  • Mark read / unread — Message / Unread / "false" (read) or "true" (unread).
  • Add to a folder (label) — actionType InsertRelation, tableName FolderThreads, value {"FolderId":"{folderId}"} (the same folder ids as POST /openApi/folderThreads/assignFoldersToThreads).

More examples

Resolve threads whose order has shipped:

{ "ruleName": "Resolve shipped orders",
  "condition": { "tableName": "Order", "fieldName": "Status", "operator": "Equals", "value1": "Shipped" },
  "action":    { "tableName": "Thread", "fieldName": "Status", "value": "3", "actionType": "UpdateField" } }
        

Assign every message mentioning “refund” to a team member:

{ "ruleName": "Refunds to Anna",
  "condition": { "tableName": "Message", "fieldName": "Text", "operator": "Contain", "value1": "refund" },
  "action":    { "tableName": "Task", "fieldName": "UserId", "value": "6f1c0a2e-9d2b-4c1e-8a7f-2b3c4d5e6f70", "actionType": "UpdateField" } }
        

Label orders over 500 with a “VIP” folder:

{ "ruleName": "VIP orders",
  "condition": { "tableName": "Order", "fieldName": "OrderTotalAmount", "operator": "Between", "value1": "500", "value2": "1000000" },
  "action":    { "tableName": "FolderThreads", "value": "{\"FolderId\":\"0b4e6c1d-2f3a-4b5c-9d8e-7f6a5b4c3d2e\"}", "actionType": "InsertRelation" } }
        

Archive weekend tickets from eBay:

{ "ruleName": "Archive weekend eBay tickets",
  "condition": { "tableName": "Thread", "fieldName": "DayOfWeek", "operator": "Equals", "value1": "[0,6]" },
  "action":    { "tableName": "Thread", "fieldName": "InActive", "value": "true", "actionType": "UpdateField" } }
        

(A single rule has one condition, so “from eBay” would be a second rule or an in-app rule with two conditions.)

Give a priority to customers writing from a specific domain:

{ "ruleName": "Key account priority",
  "condition": { "tableName": "Customer", "fieldName": "Email", "operator": "EndWith", "value1": "@bigretailer.com" },
  "action":    { "tableName": "Thread", "fieldName": "PriorityId", "value": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "actionType": "UpdateField" } }
        

Errors

  • 400 with { "error": "…" } — a required field is missing, the table or column does not exist, the value does not convert to the column’s type, Between on a number lacks value2, or relations does not lead to tableName. The message names the problem, e.g. Problems with input MessageRule: Can't find field 'IsRead' in table 'Thread'.
  • 401 — not authenticated.

The rule is scoped to the current company; the create is recorded in the automation change log.

The rule to create.

Create or replace an automation rule. The same shape is used for create and update.

This is a simplified rule: exactly one condition and one action. Every incoming message is checked against the condition and, when it matches, the action is applied to that message’s thread. (The in-app rules engine supports multi-condition expressions; the Open API intentionally keeps a single condition/action for simplicity.)

object
ruleName
required

Human-readable rule name, shown in the app and in the thread change log. Required.

string
>= 1 characters
priority

Execution order; lower numbers run first. Leave 0 to place the rule after all existing rules.

integer format: int32
inActive

Set true to create/keep the rule disabled. Defaults to enabled.

boolean
nullable
condition
required

The condition that must match for a rule to fire. It reads one field of one table, reached from the incoming message, and compares it with value1 (and value2 for Between).

object
tableName
required

The table to read: Message, Thread, Customer, Order, Task or Product (case-sensitive). Required.

string
>= 1 characters
fieldName
required

The column of tableName to compare (case-sensitive), e.g. Subject on Thread, Text on Message, Email on Customer. See the endpoint description for the catalog per table. Required.

string
>= 1 characters
operator
integer format: int32
Allowed values: 0 - Contain 1 - NotContain 2 - StartWith 3 - EndWith 4 - Equals 5 - Between
value1
required

The value to compare with, always sent as a string. Text: the fragment or exact value. Numbers: "100". Booleans: "true"/"false". Enums (thread status, marketplace): the numeric value, e.g. "3". Dates: a number of days ago ("7" = 7 days ago, must be 0 or greater) or an ISO date such as "2026-01-31". Required.

string
>= 1 characters
value2

The upper bound for Between. Required for numeric ranges; for dates it is the “newer” bound and may be omitted to mean “up to now”.

string
nullable
relations

Navigation path from Message to tableName, segments joined with &. Optional: it is filled in automatically for the documented tables (Thread → "Thread", Customer → "Thread&Customer", Order → "Thread&Order", Task → "Thread&Tasks"); Message and Product need none.

string
nullable
action
required

A single action applied to the matching message’s thread when the rule’s condition matches.

object
tableName
required

The table to change: Thread, Message or Task for UpdateField; FolderThreads for InsertRelation (case-sensitive). Required.

string
>= 1 characters
fieldName

The column to set (case-sensitive), e.g. Status, InActive, PriorityId on Thread; Unread on Message; UserId on Task. Required when actionType is UpdateField; ignored for InsertRelation.

string
nullable
value
required

For UpdateField: the new value as a string — "3", "true", a GUID. For InsertRelation: a JSON object with the columns of the row to insert, e.g. {"FolderId":"4f6d…"} for FolderThreads. Required.

string
>= 1 characters
actionType
integer format: int32
Allowed values: 0 - UpdateField 2 - InsertRelation
relations

Navigation path from Message to tableName, segments joined with &. Optional: filled in automatically for the documented tables (Thread → "Thread", Task → "Thread&Tasks", FolderThreads → "Thread&FolderThreads"); Message needs none.

string
nullable

Example

{
"ruleName": "Mark support reports read",
"condition": {
"tableName": "Thread",
"fieldName": "Subject",
"value1": "product support report"
},
"action": {
"tableName": "Message",
"fieldName": "Unread",
"value": "false"
}
}

The rule was created and is returned.

Media typeapplication/json

An automation rule. When an incoming message matches the condition, the action is applied automatically.

The Open API represents a rule as a single condition and a single action. A rule created elsewhere with multiple conditions/actions is shown here by its first condition and first action.

object
id

Unique identifier of the rule.

string format: uuid
ruleName

Human-readable rule name.

string
nullable
priority

Execution priority; lower numbers run first.

integer format: int32
inActive

When true the rule is disabled.

boolean
nullable
condition

The condition that must match for an automation rule to fire.

object
id

Unique identifier of the condition.

string format: uuid
tableName

The entity the condition reads, e.g. Message, Thread, Customer, Order, Product.

string
nullable
fieldName

The field on tableName to compare, e.g. Text, Status, Marketplace.

string
nullable
operator
integer format: int32
Allowed values: 0 - Contain 1 - NotContain 2 - StartWith 3 - EndWith 4 - Equals 5 - Between
value1

Primary comparison value.

string
nullable
value2

Secondary value, used only with the Between operator.

string
nullable
relations

Navigation path from Message to the target table when the field is not directly on Message, e.g. "Thread".

string
nullable
action

A single action applied when an automation rule matches.

object
id

Unique identifier of the action.

string format: uuid
tableName

The entity the action modifies, e.g. Thread, Task, Message, FolderThreads.

string
nullable
fieldName

The field to set (for UpdateField).

string
nullable
value

For UpdateField: the scalar value to set. For InsertRelation: a JSON object describing the record to insert.

string
nullable
actionType
integer format: int32
Allowed values: 0 - UpdateField 2 - InsertRelation
relations

Navigation path when the action targets a table related to the thread/message.

string
nullable

Example

{
"id": "1d3f5a7c-9e2b-4d6f-8a0c-2e4f6a8c0e2b",
"ruleName": "Mark support reports read",
"priority": 7,
"inActive": null,
"condition": {
"id": "4b6d8f0a-2c4e-4f6a-9b1d-3f5a7c9e1b3d",
"tableName": "Thread",
"fieldName": "Subject",
"value1": "product support report",
"value2": null,
"relations": "Thread"
},
"action": {
"id": "6e8a0c2e-4a6c-4e8a-8c0e-5a7c9e1b3d5f",
"tableName": "Message",
"fieldName": "Unread",
"value": "false",
"relations": null
}
}

The request is invalid; the body’s error says why.

User is not authenticated or authorized.