# Recommendations

Configure related-product and recently-viewed storefront recommendations.

Recommendations combine explicit curation with an ordered automatic rule chain. Pinned products are shown first, then rules fill the remaining positions. Exclusions hide products from all recommendations, including pinned products and Recently viewed. The free-product policy affects automatic selection only; pinned free products remain eligible. Reads use `read_products`, and writes use `write_products`.

Settings apply across storefronts. `include_subcategories` affects only same-category rules. Recently viewed history follows the configured window and consent policy. List responses include compact product references so integrations can render them without one request per product.

## Endpoints

## Recommendation limits

`GET /api/2025-01/recommendations/limits`

Use this response to build controls; do not hardcode limits or enum values. `rail_min_limit`/`rail_max_limit` bound both rail settings, `pins_max_per_product` bounds one product's pins, `page_size_options` are the page sizes for the pin and exclusion lists (each at most `list_max_limit`).

Scope: `read_products`

```curl
curl 'https://api-store.tringify.com/api/2025-01/recommendations/limits' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"rail_min_limit":4,"rail_max_limit":24,"rail_default_limit":12,"history_window_options":[30,60,90],"rule_match_kinds":["same_category","same_brand","same_vendor","shares_tag","same_collection","same_attribute","store_wide","bought_together"],"rule_sorts":["best_selling","newest","price_asc","price_desc"],"rules_max_per_store":5,"cross_device_modes":["off","logged_in_with_consent"],"exclusions_max_per_store":500,"list_default_limit":25,"list_max_limit":200,"page_size_options":[20,50,100],"pins_max_per_product":24}}
```

## Get recommendation settings

`GET /api/2025-01/recommendations/settings`

These settings govern related-product and recently-viewed rails across storefronts. `related_limit` and `recently_viewed_limit` are the most products each rail returns; a theme section can show fewer.

Scope: `read_products`

```curl
curl 'https://api-store.tringify.com/api/2025-01/recommendations/settings' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"settings":{"related_limit":8,"recently_viewed_enabled":true,"recently_viewed_limit":8,"history_window_days":30,"hide_out_of_stock":true,"exclude_free_products":true,"cross_device_history":"off"}}}
```

## Update recommendation settings

`PUT /api/2025-01/recommendations/settings`

Send the complete settings object returned by GET. The rail limits must be within `rail_min_limit`–`rail_max_limit`, `history_window_days` one of `history_window_options`, and `cross_device_history` one of `cross_device_modes`. A successful update publishes `recommendations/settings/update`.

Scope: `write_products`

```curl
curl -X PUT 'https://api-store.tringify.com/api/2025-01/recommendations/settings' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "cross_device_history": "off",
  "exclude_free_products": true,
  "hide_out_of_stock": true,
  "history_window_days": 30,
  "recently_viewed_enabled": true,
  "recently_viewed_limit": 8,
  "related_limit": 8
}'
```

Response:

```json
{"success":true,"data":{"settings":{"related_limit":8,"recently_viewed_enabled":true,"recently_viewed_limit":8,"history_window_days":30,"hide_out_of_stock":true,"exclude_free_products":true,"cross_device_history":"off"}}}
```

## Get recommendation rules

`GET /api/2025-01/recommendations/rules`

Rules run after pinned products and fill the rail in position order. An empty list uses the default category best-seller rule.

Scope: `read_products`

```curl
curl 'https://api-store.tringify.com/api/2025-01/recommendations/rules' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"rules":[{"match_kind":"same_category","sort":"best_selling","position":0,"include_subcategories":true}]}}
```

## Set recommendation rules

`PUT /api/2025-01/recommendations/rules`

Send rules in display order, at most `rules_max_per_store`. `same_attribute` requires an attribute id in match_value and no other rule takes one; include_subcategories applies only to same_category and is saved as false elsewhere. The same rule (kind, value, sort and include_subcategories) cannot appear twice. Rules sent from GET can be sent back unchanged: `position` is ignored and set from the array order. Send an empty array to restore the default category best-seller rule. A successful update publishes `recommendations/rules/update`.

Scope: `write_products`

```curl
curl -X PUT 'https://api-store.tringify.com/api/2025-01/recommendations/rules' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "rules": [
    {
      "include_subcategories": true,
      "match_kind": "same_category",
      "sort": "best_selling"
    }
  ]
}'
```

Response:

```json
{"success":true,"data":{"rules":[{"match_kind":"same_category","sort":"best_selling","position":0,"include_subcategories":true}]}}
```

## List curated products

`GET /api/2025-01/recommendations/pins`

Compact product references are included so clients do not need one product request per row: each carries `pin_count` (how many products it pins) and `image_url` (its main image, null without one).

Scope: `read_products`

```curl
curl 'https://api-store.tringify.com/api/2025-01/recommendations/pins?limit=25&page=1' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"product_ids":[42],"products":[{"id":42,"title":"Matte Sticker","slug":"matte-sticker","image_url":"https://cdn.example.com/stores/1/matte-sticker.jpg","pin_count":3}],"total":1}}
```

## Get pinned recommendations

`GET /api/2025-01/recommendations/pins/{productId}`

The products array follows pin order and contains display identity, including `image_url` (the main image, null without one).

Scope: `read_products`

```curl
curl 'https://api-store.tringify.com/api/2025-01/recommendations/pins/42' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"product_id":42,"pins":[{"related_product_id":17,"position":0}],"products":[{"id":17,"title":"Sticker Sheet","slug":"sticker-sheet","image_url":null}]}}
```

## Set pinned recommendations

`PUT /api/2025-01/recommendations/pins/{productId}`

Pinned products show first in the product's related rail, in this order, before the rules fill the rest. Send at most `pins_max_per_product` ids; an empty array removes every pin. A product cannot pin itself, repeat a related product or pin a gift-only product. Drafts can be pinned and show once active and published; excluded or, with hide_out_of_stock, sold-out pins are skipped. A successful update publishes `recommendations/pins/update`.

Scope: `write_products`

```curl
curl -X PUT 'https://api-store.tringify.com/api/2025-01/recommendations/pins/42' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "related_ids": [
    17,
    23
  ]
}'
```

Response:

```json
{"success":true,"data":{"product_id":42,"pins":[{"related_product_id":17,"position":0}],"products":[{"id":17,"title":"Sticker Sheet","slug":"sticker-sheet","image_url":null}]}}
```

## List recommendation exclusions

`GET /api/2025-01/recommendations/exclusions`

Compact product references are returned with the ID list, each with `image_url` (the main image, null without one).

Scope: `read_products`

```curl
curl 'https://api-store.tringify.com/api/2025-01/recommendations/exclusions?limit=25&page=1' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"product_ids":[42],"products":[{"id":42,"title":"Matte Sticker","slug":"matte-sticker","image_url":"https://cdn.example.com/stores/1/matte-sticker.jpg"}],"total":1}}
```

## Exclude a product

`POST /api/2025-01/recommendations/exclusions`

Exclusions apply to pinned products as well as automatic and recently-viewed recommendations. They do not unpublish the product. Excluding a product that is already excluded succeeds without a change. A store can exclude at most `exclusions_max_per_store` products. A change publishes `recommendations/exclusions/update`.

Scope: `write_products`

```curl
curl -X POST 'https://api-store.tringify.com/api/2025-01/recommendations/exclusions' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "product_id": 42
}'
```

Response:

```json
{"success":true,"data":{"excluded":true}}
```

## Remove a recommendation exclusion

`DELETE /api/2025-01/recommendations/exclusions/{productId}`

The operation is idempotent: removing a product that is not excluded succeeds without a change.

Scope: `write_products`

```curl
curl -X DELETE 'https://api-store.tringify.com/api/2025-01/recommendations/exclusions/42' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN"
```

Response:

```json
{"success":true,"data":{"removed":true}}
```

## Exclude products in bulk

`POST /api/2025-01/recommendations/exclusions/bulk-add`

Send at most `exclusions_max_per_store` product ids. The change runs as one transaction: products already excluded count as succeeded without a change, unknown products fail with `RECOMMENDATION_PRODUCT_NOT_FOUND`, and products past the store's `exclusions_max_per_store` ceiling fail with `RECOMMENDATION_EXCLUSIONS_TOO_MANY`, in request order. `succeeded` lists the ids now excluded, `changed` counts the ones this request added, `failed` gives each failure's code and `total` is the store's exclusion count afterwards. Repeating the request changes nothing more. Each added product publishes `recommendations/exclusions/update`.

Scope: `write_products`

```curl
curl -X POST 'https://api-store.tringify.com/api/2025-01/recommendations/exclusions/bulk-add' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "product_ids": [
    42,
    43
  ]
}'
```

Response:

```json
{"success":true,"data":{"succeeded":[42,43],"changed":2,"failed":[{"product_id":99,"code":"RECOMMENDATION_PRODUCT_NOT_FOUND"}],"total":12}}
```

## Remove recommendation exclusions in bulk

`POST /api/2025-01/recommendations/exclusions/bulk-remove`

Send at most `exclusions_max_per_store` product ids. The change runs as one transaction: products that are not excluded count as succeeded without a change and unknown products fail with `RECOMMENDATION_PRODUCT_NOT_FOUND`. `succeeded` lists the ids no longer excluded, `changed` counts the ones this request removed, `failed` gives each failure's code and `total` is the store's exclusion count afterwards. Each removed product publishes `recommendations/exclusions/update`.

Scope: `write_products`

```curl
curl -X POST 'https://api-store.tringify.com/api/2025-01/recommendations/exclusions/bulk-remove' \
  -H "Authorization: Bearer YOUR_STORE_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "product_ids": [
    42,
    43
  ]
}'
```

Response:

```json
{"success":true,"data":{"succeeded":[42,43],"changed":2,"failed":[{"product_id":99,"code":"RECOMMENDATION_PRODUCT_NOT_FOUND"}],"total":12}}
```

## Webhook events

## Recommendation exclusions updated

Event: `recommendations/exclusions/update` · App scope: `read_products` · Staff permission: `online_store.recommendations:write`

Fired when a product is added to or removed from recommendation exclusions.

```json
{
  "action": "added",
  "product": {
    "id": 0,
    "slug": "star-sunglasses",
    "title": "Example"
  }
}
```

## Pinned recommendations updated

Event: `recommendations/pins/update` · App scope: `read_products` · Staff permission: `online_store.recommendations:write`

Fired when a product's pinned recommendations change.

```json
{
  "pins": [
    {
      "position": 0,
      "related_product_id": 0
    }
  ],
  "product_id": 0,
  "products": [
    {
      "id": 0,
      "slug": "summer-dress",
      "title": "Example"
    }
  ]
}
```

## Recommendation rules updated

Event: `recommendations/rules/update` · App scope: `read_products` · Staff permission: `online_store.recommendations:write`

Fired when the recommendation rule chain changes.

```json
{
  "rules": [
    {
      "include_subcategories": false,
      "match_kind": "same_category",
      "match_value": null,
      "position": 0,
      "sort": "best_selling"
    }
  ]
}
```

## Recommendation settings updated

Event: `recommendations/settings/update` · App scope: `read_products` · Staff permission: `online_store.recommendations:write`

Fired when recommendation settings change.

```json
{
  "settings": {
    "cross_device_history": "off",
    "exclude_free_products": false,
    "hide_out_of_stock": false,
    "history_window_days": 0,
    "recently_viewed_enabled": false,
    "recently_viewed_limit": 0,
    "related_limit": 0
  }
}
```

