> ## Documentation Index
> Fetch the complete documentation index at: https://developer.rocket.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# Create or Update Livechat Triggers

> Permission required: `view-livechat-manager`

See the <a href="https://docs.rocket.chat/docs/livechat-triggers" target="_blank">Livechat Triggers</a> guide for more information.

## OpenAPI

````json POST /api/v1/livechat/triggers
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Omnichannel"
  },
  "servers": [
    {
      "url": "https://apiexplorer.support.rocket.chat"
    }
  ],
  "tags": [
    {
      "name": "Omnichannel Users"
    },
    {
      "name": "Omnichannel Agents"
    },
    {
      "name": "Omnichannel Monitors"
    },
    {
      "name": "Omnichannel Visitors"
    },
    {
      "name": "Omnichannel Contacts"
    },
    {
      "name": "Omnichannel Rooms"
    },
    {
      "name": "Omnichannel Departments"
    },
    {
      "name": "Omnichannel Custom Fields"
    },
    {
      "name": "Omnichannel Business Hours"
    },
    {
      "name": "Omnichannel Priorities"
    },
    {
      "name": "Omnichannel Tags"
    },
    {
      "name": "Omnichannel Units"
    },
    {
      "name": "SLA Policies"
    },
    {
      "name": "Canned Responses"
    },
    {
      "name": "Omnichannel Transcript"
    },
    {
      "name": "Omnichannel Statistics"
    },
    {
      "name": "Omnichannel Agent Stats"
    },
    {
      "name": "Omnichannel Dashboards"
    },
    {
      "name": "Reports"
    },
    {
      "name": "Omnichannel Inquiries"
    },
    {
      "name": "Omnichannel Webhooks"
    },
    {
      "name": "Livechat"
    },
    {
      "name": "Livechat Appearance"
    },
    {
      "name": "Livechat Triggers"
    },
    {
      "name": "Livechat Messages"
    },
    {
      "name": "Livechat Page Visited"
    }
  ],
  "paths": {
    "/api/v1/livechat/triggers": {
      "post": {
        "summary": "Create or Update Livechat Triggers",
        "tags": [
          "Livechat Triggers"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/trueSuccess"
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "error": {
                      "type": "string"
                    },
                    "errorType": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "Example 1": {
                    "value": {
                      "success": "false",
                      "error": "must have required property 'description' [invalid-params]",
                      "errorType": "invalid-params"
                    }
                  },
                  "Example 2": {
                    "value": {
                      "success": "false",
                      "error": "must be equal to one of the allowed values [invalid-params]",
                      "errorType": "invalid-params"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/authorizationError"
          },
          "403": {
            "$ref": "#/components/responses/permissionError"
          }
        },
        "operationId": "post-api-v1-livechat-triggers",
        "description": "Permission required: `view-livechat-manager`\n\nSee the <a href=\"https://docs.rocket.chat/docs/livechat-triggers\" target=\"_blank\">Livechat Triggers</a> guide for more information.",
        "parameters": [
          {
            "$ref": "#/components/parameters/AuthToken"
          },
          {
            "$ref": "#/components/parameters/UserId"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "description",
                  "enabled",
                  "runOnce",
                  "conditions",
                  "actions"
                ],
                "properties": {
                  "_id": {
                    "type": "string",
                    "description": "If you want to update a trigger, enter the trigger ID.",
                    "example": "65fa8f42482d68e364"
                  },
                  "name": {
                    "type": "string",
                    "description": "Enter a name for the trigger.",
                    "example": "test-trigger"
                  },
                  "description": {
                    "type": "string",
                    "description": "Enter a description for the trigger.",
                    "example": "Test trigger with the endpoint."
                  },
                  "enabled": {
                    "type": "boolean",
                    "description": "Whether the trigger is enabled for use or not.",
                    "default": "true"
                  },
                  "runOnce": {
                    "type": "boolean",
                    "description": "Whether the trigger will be run only once for each visitor.",
                    "default": "false"
                  },
                  "conditions": {
                    "type": "array",
                    "description": "Enter the conditions for the trigger to execute.",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "The condition that should take place for the trigger to execute. The possible values are:\n* `time-on-site`: The amount of time a visitor is on the site.\n* `page-url`: The site URL that a visitor visits.\n* `chat-opened-by-visitor`: The chat is opened by the visitor.\n* `after-guest-registration`: The guest is registered to the chat."
                        },
                        "value": {
                          "oneOf": [
                            {
                              "type": "number"
                            },
                            {
                              "type": "string"
                            }
                          ],
                          "description": "Enter the value of the `page-url` (string) or the `time-on-site`, in seconds (number). Otherwise, you can enter `null`."
                        }
                      }
                    }
                  },
                  "actions": {
                    "type": "array",
                    "description": "The actions that take place once the trigger is executed.",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "The name of the trigger action that takes place. The possible values are:\r\n* `send-message`: A message is sent to the visitor.\r\n* `use-external-service`: An external service is used for the trigger action."
                        },
                        "params": {
                          "type": "object",
                          "description": "Enter the parameter values for the trigger action.",
                          "properties": {
                            "sender": {
                              "type": "string",
                              "description": "The sender of the trigger action. The possible values are:\r\n* `queue`: Impersonate the next available agent in the queue.\r\n* `custom`: Use a specific agent or bot."
                            },
                            "name": {
                              "type": "string",
                              "description": "Enter the name of the agent or bot that you want to use, if the `sender` is `custom`."
                            },
                            "msg": {
                              "type": "string",
                              "description": "Enter a message for the visitor, if the action `name` is `send-message`."
                            },
                            "serviceUrl": {
                              "type": "string",
                              "description": "Enter the external service URL you want to use, if the action `name` is `use-external-service`.",
                              "example": "http://localhost:3000/api/vX"
                            },
                            "serviceTimeout": {
                              "type": "number",
                              "description": "Enter the service timeout value, in seconds, if the action `name` is `use-external-service`.",
                              "example": "5000"
                            },
                            "serviceFallbackMessage": {
                              "type": "string",
                              "description": "Enter a message when the service is not accessible, if the action `name` is `use-external-service`.",
                              "example": "Were sorry, we cannot complete your request"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              },
              "examples": {
                "Example 1": {
                  "value": {
                    "name": "api-trigger",
                    "description": "testing create trigger endpoint",
                    "enabled": "false",
                    "runOnce": "true",
                    "conditions": [
                      {
                        "name": "chat-opened-by-visitor",
                        "value": "0"
                      }
                    ],
                    "actions": [
                      {
                        "name": "send-message",
                        "params": {
                          "sender": "queue",
                          "msg": "hello world"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "trueSuccess": {
        "description": "OK",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "success": {
                  "type": "boolean"
                }
              }
            },
            "examples": {
              "Success": {
                "value": {
                  "success": "true"
                }
              }
            }
          }
        }
      },
      "authorizationError": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            },
            "examples": {
              "Authorization Error": {
                "value": {
                  "status": "error",
                  "message": "You must be logged in to do this."
                }
              }
            }
          }
        }
      },
      "permissionError": {
        "description": "Forbidden",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "success": {
                  "type": "boolean"
                },
                "error": {
                  "type": "string"
                }
              }
            },
            "examples": {
              "Permission Error": {
                "value": {
                  "success": "false",
                  "error": "User does not have the permissions required for this action [error-unauthorized]"
                }
              },
              "Unauthorized": {
                "value": {
                  "success": "false",
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "parameters": {
      "AuthToken": {
        "name": "X-Auth-Token",
        "in": "header",
        "description": "The `authToken` of the authenticated user.",
        "required": "true",
        "schema": {
          "type": "string"
        },
        "example": "RScctEHSmLGZGywfIhWyRpyofhKOiMoUIpimhvheU3f"
      },
      "UserId": {
        "name": "X-User-Id",
        "in": "header",
        "description": "The `userId` of the authenticated user.",
        "required": "true",
        "schema": {
          "type": "string"
        },
        "example": "rbAXPnMktTFbNpwtJ"
      }
    }
  }
}
````

