POST
Get a recommendation decision
Você manda o momento e o seu contexto; volta uma recomendação com cada produto completo, pronto para mostrar sem outra chamada. Uma lista vazia também é válida, e traz o motivo.

Os cinco momentos

Se falta o que o momento pede, a resposta é 400 invalid_request e pointer diz qual campo. Um context_item_id em um momento de carrinho volta em context, mas não muda a recomendação.

A requisição não escolhe a loja

Não existe store_id: o servidor tira a loja da chave e valida que connection_id seja dela. Nenhum campo do corpo lê dados alheios.

O visitante

visitor é opcional: { visitor_id, session_id? }, com a forma vis_… e ses_…. Nunca faz a requisição falhar: com outra forma, é descartado e não é salvo. Nunca é um dado do comprador: Visitante e contexto. Cada requisição fica registrada com seu visitante e a recomendação que devolveu: assim um clique é ligado depois a ela.

O que devolve

A resposta é a recomendação (na API, Decision: a lista de produtos recomendados para aquele momento).
  • decision_id: o id da recomendação, único por resposta. Duas requisições iguais são duas recomendações.
  • request_id: o mesmo valor do header X-Request-ID.
  • context: de onde partiu a recomendação. shooter traz o produto de partida, e cart_items, o carrinho como chegou.
  • results[]: item_id, variant_id?, position, reason_codes[] e product, completo: item, taxonomia, variantes com preço e disponibilidade.
Não há score nem id da sugestão do motor. O ranking é a position, e um teste do contrato falha se aparecer uma pontuação.
product é opcional: se não deu para lê-lo, o resultado sai sem ele e se resolve com ler o catálogo. item.description viaja como a plataforma a manda; a Nuvemshop manda HTML, então sanitize. reason_codes aparece na recomendação e em cada resultado: um explica a resposta inteira, o outro essa posição. Numa lista vazia, diz o que aconteceu:

cart_items é um array de objetos

Opcional (omitido é []), mas nunca null. Cada elemento é { item_id, variant_id, quantity }, com quantity ≥ 1. Passado o limite, a resposta é cart_items_limit_exceeded, com max_items_per_cart e actual_items.

Autorizações

Authorization
string
header
obrigatório

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Corpo

application/json

Every field but the connection, the placement and the surface is optional in the schema, and the surface decides what is needed. pdp, cart and checkout need a shooter (context_item_id) or at least one cart item. success-page, in-checkout and carousel need at least one cart item; a shooter sent with them is recorded and echoed but does not drive the engine. A request with neither is a 400. cart_id is the store's own id for the cart and belongs with cart_items: send it whenever the cart is not empty. It is not required by the schema — a request without it is served normally — but the decision it produces cannot be tied back to a sale.

connection_id
string
obrigatório
Minimum string length: 1
placement_key
string
obrigatório
Minimum string length: 1
surface
enum<string>
obrigatório

The storefront moment that asks for recommendations. Three moments start from a product the shopper is looking at or just added (the shooter, context_item_id): pdp (product page), cart (right after adding to the cart) and checkout (when the purchase starts). The other three read only the cart: success-page (purchase finished), in-checkout (inside the checkout) and carousel (the cart page).

Opções disponíveis:
pdp,
cart,
checkout,
success-page,
in-checkout,
carousel
Minimum string length: 1
context_item_id
string

The shooter item (the product the moment starts from), when the moment has one.

Minimum string length: 1
cart_items
object[]

The cart as the storefront sees it. Omitted means empty.

cart_id
string

The store's own id for this cart. Send it whenever cart_items is not empty: it is what ties the sale back to the offer once the order comes in through the webhook. A request that carries a cart without it still answers 200 and still serves a recommendation, but that decision cannot be attributed to a sale later.

Required string length: 1 - 256
visitor
object

Pseudonymous identity of the browser that asks. The storefront SDK creates and keeps it; it carries no personal data and must never be an email, a phone number or a platform customer id. Sending it is optional, and a visitor that does not match this shape never fails the request: the server drops it, answers without it and does not store it.

client
object

What the storefront SDK can read in the browser about the request. Every field is optional and sending it never fails the request: a context the server cannot read is dropped and the recommendation is served anyway. The server also records the client IP, User-Agent, Accept-Language, Origin and Referer from the HTTP request; none of this is returned.

Resposta

Recommendation decision

decision_id
string
obrigatório

Unique per response. Signals about what was shown reference it.

Minimum string length: 1
request_id
string
obrigatório

The same value as the X-Request-ID response header.

Minimum string length: 1
store_id
string
obrigatório
Minimum string length: 1
connection_id
string
obrigatório
Minimum string length: 1
placement_key
string
obrigatório
Minimum string length: 1
surface
enum<string>
obrigatório

The storefront moment that asks for recommendations. Three moments start from a product the shopper is looking at or just added (the shooter, context_item_id): pdp (product page), cart (right after adding to the cart) and checkout (when the purchase starts). The other three read only the cart: success-page (purchase finished), in-checkout (inside the checkout) and carousel (the cart page).

Opções disponíveis:
pdp,
cart,
checkout,
success-page,
in-checkout,
carousel
Minimum string length: 1
context
object
obrigatório

What the decision was taken from, echoed so the storefront does not have to remember it.

results
object[]
obrigatório
reason_codes
string[]
obrigatório
Minimum string length: 1
generated_at
string<date-time>
obrigatório
visitor
object

Pseudonymous identity of the browser that asks. The storefront SDK creates and keeps it; it carries no personal data and must never be an email, a phone number or a platform customer id. Sending it is optional, and a visitor that does not match this shape never fails the request: the server drops it, answers without it and does not store it.