Skip to main content

Create Pattern

This API allows you to create a new pattern.

📍 Endpoint

POST {base_url}/api/user/pattern

🧾 Headers

KeyValue
AuthorizationYOUR_TOKEN_HERE
Content-Typeapplication/json

📤 Request Body

{
"title": "test pattern",
"description": "پترن تستی",
"is_share": false,
"message": "پترن تستی %var% . کد شما %code%",
"website": "https://yoursite.com",
"variable": [
{
"name": "var",
"type": "string"
},
{
"name": "code",
"type": "integer"
}
]
}

📝 Parameters

ParameterTypeRequiredDescription
titlestringNoThe title of the pattern.
descriptionstringYesA brief description of the pattern.
is_sharebooleanYesWhether the pattern can be shared with sub users. Default is false.
messagestringYesThe message template containing variables.
websitestringNoThe website associated with the pattern.
variablearrayYesAn array of variable objects defining the variables used in the message.
namestringYesThe name of the variable.
typestringYesThe type of the variable (string, integer).

✅ Success Response

{
"data": {
"id": "683c0ef4ad9979cd75066974",
"title": "test pattern",
"username": "username",
"pattern_code": "jhaskdab45s6f4sfw",
"pattern_message": "پترن تستی %var% . کد شما %code%",
"admin_comment": null,
"pattern_description": "پترن تستی",
"pattern_status": "pending",
"pattern_is_share": false,
"reject_text": "",
"type": "sms",
"variable": [
{
"name": "var",
"type": "string",
"len": 40
},
{
"name": "code",
"type": "integer",
"len": 40
}
],
"delimiter": "%",
"updated_at": "2025-06-01T08:27:32.244000Z",
"time": 1748766452,
"pattern_state_revision": null,
"pattern_message_revision": null,
"pattern_is_share_revision": null,
"pattern_description_revision": null,
"pattern_delimiter_revision": null,
"pattern_state_log": null,
"pattern_message_log": null,
"pattern_is_share_log": null,
"pattern_description_log": null,
"pattern_delimiter_log": null
},
"meta": {
"status": true,
"message": "انجام شد",
"message_code": "200-1"
}
}

❌ Error Response — Invalid or Expired Token (401)

{
"data": null,
"meta": {
"status": false,
"message": "اطلاعات وارد شده صحیح نمی باشد",
"message_parameters": [],
"message_code": "400-1",
"errors": {}
}
}

❌ Error Response — Invalid Request (422)

{
"data": null,
"meta": {
"status": false,
"message": "تکمیل گزینه description الزامی است (و 1 خطای دیگر)",
"message_parameters": [],
"message_code": "400-2",
"errors": {
"description": [
"تکمیل گزینه description الزامی است"
],
"message": [
"تکمیل گزینه message الزامی است"
],
"variable.0.name": [
"تکمیل گزینه variable.0.name الزامی است"
],
"variable.0.type": [
"تکمیل گزینه variable.0.type الزامی است"
]
}
}
}

🧪 Example Request

curl --location '{base_url}/api/patterns/normal' \
--header 'Content-Type: application/json' \
--header 'Authorization: Your Apikey/Token' \
--data-raw '{
"title": "test pattern",
"description": "پترن تستی",
"is_share": false,
"message": "پترن تستی %var% . کد شما %code%",
"variable": [
{
"name": "var",
"type": "string"
},
{
"name": "code",
"type": "integer"
}
]
}'