Techdocs
Search…
Querying Category Merchandising Products
Nosto's category merchandising APIs are meant to be used for resorting your existing product listing pages. It has support for listing the products in the order defined within Nosto for different categories, including paging and filtering support. It doesn't support taking over the product listing pages fully as it doesn't include support for creating category specific filters and calculating their facet counts. The expected implementation leveraging these APIs would keep on using their current solution for building most of the product list pages, but swap the shown products with the information retrieved from this APIs results.
You can query category merchandising products using the query below:
1
curl -0 -v -X POST https://api.nosto.com/v1/graphql \
2
-u ":<token>" \
3
-H 'Content-Type: application/graphql' \
4
-d @- << EOF
5
query {
6
session(by: BY_CID, id: $customerId) {
7
id
8
recos(
9
preview: false,
10
image: VERSION_ORIGINAL,
11
addAttributionParameters: true) {
12
category(
13
category: $categoryName,
14
minProducts: 1,
15
maxProducts: 10
16
) {
17
primary {
18
productId
19
url
20
}
21
batchToken
22
totalPrimaryCount
23
resultId
24
}
25
}
26
}
27
}
28
EOF
Copied!

Session Lookup

In order to be able to provide personalized results, we will need to look up a session either by id or by reference. You read more about managing sessions on our onsite sessions wiki page.

Attribution Parameters

Setting the addAttributionParameters parameter to true, causes attribution parameters to be automatically rendered in product URLs. For example, the url https://example.com/product becomes https://example.com/product?nosto_source=cmp&amp;nosto=5e5e09f060b232790cbbccbf. These parameters allow our client script to track the performance of Category Merchandising results.
If you wish to handle attribution parameters manually, the addAttributionParameters parameter can either be set to false or can be omitted. In order to build the attribution parameters yourself, you will need to set nosto_source to cmp and the nosto parameter to the resultId from the GraphQL response.

Event handling

Graphql calls using CMP methods are treated as a category view by default. This behavior can be changed by including skipVCEvent: true into the graphql request. All product URLs on a category page must be appended with #nosto_cmp fragment. An example of such a product URL would be www.test-store.com/product1#nosto_cmp where #nosto_cmp is the added fragment.

Pagination

The batchToken can be used the next batch of results. This is useful if you only wish to fetch the first 10 products when there may be thousands of results. To fetch the next batch, use the batchToken in the next query like in the example below:
1
curl -0 -v -X POST https://api.nosto.com/v1/graphql \
2
-u ":<token>" \
3
-H 'Content-Type: application/graphql' \
4
-d @- << EOF
5
query {
6
session(by: BY_CID, id: $customerId) {
7
id
8
recos(
9
preview: false,
10
image: VERSION_ORIGINAL,
11
addAttributionParameters: true) {
12
category(
13
category: $categoryName,
14
minProducts: 1,
15
maxProducts: 10,
16
batchToken: "n200MjA2NDc0OTUyNzg1+z/wAAAAAAAA/w=="
17
) {
18
primary {
19
productId
20
url
21
}
22
batchToken
23
totalPrimaryCount
24
resultId
25
}
26
}
27
}
28
}
29
EOF
Copied!
If you wish to skip the first number of pages, you can use the skipPages parameter instead of the batchToken. A page size is calculated from the maxProducts parameter.

Filtering Results

Results can be filtered by specifying the include and exclude parameters. You can explore more parameters in the GraphQL Playground
1
curl -0 -v -X POST https://api.nosto.com/v1/graphql \
2
-u ":<token>" \
3
-H 'Content-Type: application/graphql' \
4
-d @- << EOF
5
query {
6
session(by: BY_CID, id: $customerId) {
7
id
8
recos(
9
preview: false,
10
image: VERSION_ORIGINAL,
11
addAttributionParameters: true) {
12
category(
13
category: $categoryName,
14
minProducts: 1,
15
maxProducts: 10,
16
include: {
17
customFields: [{
18
attribute: "color",
19
values: ["white"]
20
}]
21
}
22
exclude: {
23
discounted: true
24
}
25
) {
26
primary {
27
productId
28
url
29
}
30
batchToken
31
totalPrimaryCount
32
resultId
33
}
34
}
35
}
36
}
37
EOF
Copied!
Last modified 2mo ago