Web trigger rule
Introduction
A web trigger rule determines whether a new workflow should be triggered when Casewhere receives an HTTP request. Learn more about web triggers here.
Rule syntax
Keywords
The following keywords are available in web trigger rules:
| Name | Type | Description |
|---|---|---|
| @parameters | IDictionary<string, object> | The query string parameters from the request URL. |
| @routeParameters | IDictionary<string, object> | The route parameters from the URL pattern. For example, for /dynamic/vehicle_inspections/{id}, access @routeParameters["id"]. |
| @headers | IDictionary<string, IEnumerable |
The HTTP request header key-value pairs. |
| @body | dynamic | The request payload. Access attributes using the dot operator (e.g., @body.phoneNumber). |
| @user | DslUser | The user in context. Only available when Accessible From Worker Site is enabled on the web trigger; otherwise the rule fails to compile. See access rule for the DslUser reference. |
| @apiFactory | IManagedApiFactory | To construct Casewhere API objects. Read here for the full list of available APIs. |
A web trigger rule returns true to run the workflow, or false to reject the request with HTTP 400 Bad Request. To return a custom status, return an object with StatusCode and Message — the request is rejected unless StatusCode is 200. Example 2 below returns 401 for an invalid API key.
Examples
Example 1: Filter by query string
For the request api/product?category_id=1, access the query string parameter:
@parameters["category_id"].ToString() == "1"
Example 2: Validate API key
Verify the API key in the request headers and return a structured error response if validation fails.
#predicate
// Parse the request header
var dataApi = @apiFactory.Get<IDataApi>();
if (!@headers.ContainsKey("Authorization"))
{
return new
{
StatusCode = 400,
Message = "Authorization header is missing"
};
}
// Query Api Keys in DB
var headerKey = @headers["Authorization"].First();
var filter = FilterBuilder.Create().Eq("ApiKey", headerKey).Eq("Active", true).Build();
var found = dataApi.Any("Applications", filter);
if (!found)
{
return new
{
StatusCode = 401,
Message = "Invalid Api key"
};
}
return true;