Skip to content

Add a rule

POST
/v1/apps/{appId}/rules
curl --request POST \
--url https://api.shoofai.com/v1/apps/demo-store/rules \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 4f1c2a9e-7b1d-4c0e-9a51-2d3f6b8e0c47' \
--header 'x-shoof-api-key: <x-shoof-api-key>' \
--data '{ "description": "Pin the new collection for \"summer\"", "pattern": "summer", "match": "contains", "pins": [ { "id": "sku-77-en", "position": 1 } ] }'

Adds one rule after the existing ones. The body is the rule, or {"rule": {...}}. The response has its id.

appId
required
string

The app’s id, shown in the dashboard (for example ali-sport-goods). demo-store is the public demo app.

Example

demo-store
Idempotency-Key
string
>= 1 characters <= 255 characters /^[\x21-\x7e]+$/

A unique value, such as a UUID, that makes retrying this request safe. The first request with a key runs; for 24 hours a retry with the same key and the same body gets the first response again, with Idempotent-Replayed: true, and doesn’t run a second time. The same key with a different body is refused (409 idempotency_key_reused), and so is a retry while the first request is still running (409 idempotency_key_in_use). Keys belong to the app. Only successful responses are kept: after an error the key is free again.

Example

4f1c2a9e-7b1d-4c0e-9a51-2d3f6b8e0c47
Media typeapplication/json
object
id
string
<= 64 characters
description
string
<= 256 characters
enabled
boolean
default: true
pattern
required

Not empty, unless match is any.

string
<= 256 characters
match
string
default: is
Allowed values: is contains starts_with any
lang
string
pins
Array<object>
<= 50 items
object
id
string
position
integer
>= 1 <= 100
hides
Array<string>
<= 200 items
filters

Field to value. Fields are AND-ed; a list matches any of its values. See Filters.

object
key
additional properties
One of:
One of:
string
replaceQuery
string
validFrom

ISO 8601.

string
validUntil

ISO 8601.

string
contexts
Array<string>
<= 20 items
boosts
Array<object>
<= 20 items
object
filters
required

Field to value. Fields are AND-ed; a list matches any of its values. See Filters.

object
key
additional properties
One of:
One of:
string
factor
number
default: 2 >= 1 <= 100
buries
Array<object>
<= 20 items
object
filters
required

Field to value. Fields are AND-ed; a list matches any of its values. See Filters.

object
key
additional properties
One of:
One of:
string
factor
number
default: 2 >= 1 <= 100
banner
object
title
required
string
<= 200 characters
text
string
<= 500 characters
imageUrl
string format: uri
linkUrl
string format: uri
userData

Any JSON up to 8 KB, returned in the search response.

Example

{
"description": "Pin the new collection for \"summer\"",
"pattern": "summer",
"match": "contains",
"pins": [
{
"id": "sku-77-en",
"position": 1
}
]
}

The saved rule, with its id.

Media typeapplication/json
object
rule
object
id
string
<= 64 characters
description
string
<= 256 characters
enabled
boolean
default: true
pattern
required

Not empty, unless match is any.

string
<= 256 characters
match
string
default: is
Allowed values: is contains starts_with any
lang
string
pins
Array<object>
<= 50 items
object
id
string
position
integer
>= 1 <= 100
hides
Array<string>
<= 200 items
filters

Field to value. Fields are AND-ed; a list matches any of its values. See Filters.

object
key
additional properties
One of:
One of:
string
replaceQuery
string
validFrom

ISO 8601.

string
validUntil

ISO 8601.

string
contexts
Array<string>
<= 20 items
boosts
Array<object>
<= 20 items
object
filters
required

Field to value. Fields are AND-ed; a list matches any of its values. See Filters.

object
key
additional properties
One of:
One of:
string
factor
number
default: 2 >= 1 <= 100
buries
Array<object>
<= 20 items
object
filters
required

Field to value. Fields are AND-ed; a list matches any of its values. See Filters.

object
key
additional properties
One of:
One of:
string
factor
number
default: 2 >= 1 <= 100
banner
object
title
required
string
<= 200 characters
text
string
<= 500 characters
imageUrl
string format: uri
linkUrl
string format: uri
userData

Any JSON up to 8 KB, returned in the search response.

Example

{
"rule": {
"enabled": true,
"match": "is",
"filters": {
"brand": [
"Nike",
"Asics"
],
"price": {
"gte": 50,
"lte": 150
},
"in_stock": true
},
"boosts": [
{
"filters": {
"brand": [
"Nike",
"Asics"
],
"price": {
"gte": 50,
"lte": 150
},
"in_stock": true
},
"factor": 2
}
],
"buries": [
{
"filters": {
"brand": [
"Nike",
"Asics"
],
"price": {
"gte": 50,
"lte": 150
},
"in_stock": true
},
"factor": 2
}
]
}
}

The request is invalid (bad_request). details lists each problem with its path.

Media typeapplication/json
object
error
required
object
code
required

A stable, machine-readable code.

string
message
required

A human-readable explanation.

string
details

More about the error, such as the validation problems.

Example

{
"error": {
"code": "bad_request",
"message": "Invalid request",
"details": [
{
"path": "hitsPerPage",
"message": "Must be 100 or less"
}
]
}
}

The month’s quota and the workspace’s prepaid balance are both used up, or the plan’s limit is reached (quota_exceeded). Every plan has hard limits; nothing is served first and billed later. Buying a pack in Billing adds to the balance.

Media typeapplication/json
object
error
required
object
code
required

A stable, machine-readable code.

string
message
required

A human-readable explanation.

string
details

More about the error, such as the validation problems.

Example generated

{
"error": {
"code": "example",
"message": "example",
"details": "example"
}
}

The Idempotency-Key was used for a different request (idempotency_key_reused), or the first request with it is still running (idempotency_key_in_use).

Media typeapplication/json
object
error
required
object
code
required

A stable, machine-readable code.

string
message
required

A human-readable explanation.

string
details

More about the error, such as the validation problems.

Example generated

{
"error": {
"code": "example",
"message": "example",
"details": "example"
}
}

Too many requests in this window (rate_limited). Wait Retry-After seconds, then retry.

Media typeapplication/json
object
error
required
object
code
required

A stable, machine-readable code.

string
message
required

A human-readable explanation.

string
details

More about the error, such as the validation problems.

Example

{
"error": {
"code": "rate_limited",
"message": "Rate limit exceeded"
}
}
Retry-After
integer

Seconds to wait before retrying. Sent with every 429.

RateLimit
string

What’s left in the window (IETF draft-ietf-httpapi-ratelimit-headers): the bucket’s name, r the requests left and t the seconds until the window resets. Sent on every response.

Example
"search";r=597;t=43
RateLimit-Policy
string

The bucket’s quota q per window of w seconds. Sent on every response.

Example
"search";q=600;w=60
RateLimit-Limit
integer

The requests allowed per window (the older form of RateLimit-Policy).

RateLimit-Remaining
integer

The requests left in the window.

RateLimit-Reset
integer

Seconds until the window resets.