Preview product rule conditions
Which products a draft rule's conditions match, without saving anything: the matched count and share and sample products.
POST /properties/{propertyId}/product-rules/preview
Scope read · Access Read only · Operation id product_rules.preview
Try it
productmetrics runs after productmetrics login; curl needs PM_TOKEN (see Authentication). Set $PROPERTY_ID first.
productmetrics product-rules preview \
--property-id $PROPERTY_ID \
--when-cols custom_label_0 \
--when-ops == \
--when-vals Shoes \
--jsonResponse
API response (200), shortened:
{
"data": {
"custom_field_distribution": {
"custom_label_2": {
"kind": "number",
"min": 12.5
// … 2 more fields
}
},
"moves": {
"segments": {
"total": 42,
"moves": [ … ]
// … 1 more field
},
"category_priority": [
{ … }
]
// … 2 more fields
}
// … 6 more fields
},
"request_id": "req_01JWB5CGMB8JX6K124DENP96WP"
}CLI output: productmetrics product-rules preview --json prints { "ok": true, "data": …, "request_id": "…" } with the same data.
Before you call
With draft_rule and include_moves, also the segment and priority moves the rule would cause next to the saved rules. Call it before product_rules.create or product_rules.update. Without Product Segmentation subscription only two sample products are returned.
Path parameters
| Name | Type | Description |
|---|---|---|
propertyId | string (uuid) | A property_id from properties.list. |
Query parameters
| Name | Type | Required | Description |
|---|---|---|---|
feed_scope | string | No | Which feed of the property: a feed id, or all for the property-wide settings. Omitted: the property’s default scope. |
Body
| Name | Type | Required | Description |
|---|---|---|---|
draft_custom_fields | any | No | Custom field settings to preview with, as feed_source_settings.get returns them. |
segment_lock_snapshot | boolean | No | Include the segments currently locked by keep rules in the preview. |
when_cols | array of string | Yes | The product column each condition reads (for example custom_label_0 or brand), one per condition. |
when_ops | array of enum | Yes | The operator of each condition, in the order of when_cols. Each one of ==, !=, <, <=, >, >=, contains, not_contains, in, not_in, regex, is_empty, is_not_empty. |
when_vals | array of string | Yes | The value each condition compares with, in the order of when_cols. |
when_logic | array of enum | No | How each condition joins the next (AND or OR), in the order of when_cols. Each one of AND, OR. |
when_tree | object | No | The conditions as a tree: match all or any of items, which can hold nested groups. |
when_tree.match | enum | Yes | all: every item must match; any: one is enough. One of all, any. |
when_tree.items | array of object | Yes | The conditions and nested groups at this level. At least 1 item. |
when_tree.items[].column | string | No | The product column the condition reads. |
when_tree.items[].operator | enum | No | How the column is compared with value. One of ==, !=, <, <=, >, >=, contains, not_contains, in, not_in, regex, is_empty, is_not_empty. |
when_tree.items[].value | string | No | The value the column is compared with. |
when_tree.items[].match | enum | No | In a nested group: all or any of its items. One of all, any. |
when_tree.items[].items | array of object | No | In a nested group: its conditions. At least 1 item. |
draft_rule | object | No | The rule as you would save it, to preview its effect before product_rules.create or product_rules.update. |
draft_rule.rule_id | string (uuid) | No | The rule being edited: its id from product_rules.list. Leave it out for a new rule. |
draft_rule.target_cols | array of enum | Yes | The feed columns the rule writes: the product segment label, the category priority label, or both. Each one of product_segment, category_priority. At least 1 item. |
draft_rule.action | enum | Yes | = writes action_value; keep locks the products’ current segment until active_until. One of =, keep. |
draft_rule.action_value | string | Yes | The value written to target_cols with action =, for example the segment stars. |
include_moves | boolean | No | Also list the products the rule would move, not only the counts. |
Errors
A failure answers with its HTTP status and { error: { code, message, details? }, request_id }. Branch on code (stable, lower_snake); show message to the person. The CLI prints the same error with "ok": false.
{
"error": {
"code": "insufficient_scope",
"message": "This operation needs the read scope; connect again and allow it.",
"details": {
"required_scope": "read"
}
},
"request_id": "req_01JWEECPNGTHHBWMKJ5EJVG6W5"
}| Status | Code | When |
|---|---|---|
| 400 | invalid_request | A path, query or body value does not match this page. details.issues lists each location, path and message. |
| 401 | invalid_token | The token is missing, expired or revoked: sign in again (productmetrics login). The WWW-Authenticate header says why. |
| 403 | insufficient_scope | The token lacks the read scope (details.required_scope): sign in again and allow it. |
| 404 | not_found | An id in the path does not exist, or the signed-in person cannot open it. |
| 429 | rate_limited | More than 600 requests a minute for this person: wait the Retry-After seconds (60) and retry. |