Price table for logged-in users

Hello!

I develop external apps and use VTEX’s REST APIs.

I have a client that has special prices based on a rule created like this: Configurar tabelas de preços para usuários específicos

On the website, when the user is logged in, the special prices appear correctly in both search results and checkout.

I use the api/vtexid/pub/authentication/start and api/vtexid/pub/authentication/classic/validate endpoints to authenticate the user and retrieve the authCookie

{
    "authStatus": "Success",
    "promptMFA": false,
    "lastAttemptAvailable": null,
    "clientToken": null,
    "authCookie": {
        "Name": "VtexIdclientAutCookie_vendor",
        "Value": "eyJhbGciOiJFUzI1NiIsImtpZCI6IjhCMUZEMjlENzRGMzBEQzhDQzcyQjFDMzAzOTc0OEIzNDQ0REE0OTUiLCJ0eXAiOiJqd3QifQ.eyJzdWIiOiJpZ29yLm5hc3NpZkBjb3"
    },
    "accountAuthCookie": {
        "Name": "VtexIdclientAutCookie_64c257eb-e3ba-43fe-9ca2-9bc0ffaecb9e",
        "Value": "eyJhbGciOiJFUzI1NiIsImtpZCI6IjhCMUZEMjlENzRGMzBEQzhDQzcyQjFDMzAzOTc0OEIzNDQ0REE0OTUiLCJ0eXAiOiJqd3QifQ.eyJzdWIiOiJpZ29yLm5hc3NpZkBjb3JlYml6LmFnIiwiYWNjb3VudCI6InNvcnZvZWMiLCJhdWRpZW5jZSI6IndlYnN0b3JlIiwic2VzcyI6IjI2NzI1YWVlLWRhNTQtNDVmNi04Yzk3LTYwZjdiMjI0ZmJmOSIsImV4cCI6MTY4OTY4NTkyNS"
    },
    "expiresIn": 86399,
    "userId": "e7e45e20-055f-4a41-bd3b-e91e",
    "phoneNumber": null,
    "scope": null
}

I’m not sure why, but only this endpoint appears in the documentation: VTEX ID. It only generates a token for the appKey and appToken.

When I perform a search using https://{{accountName}}.{{environment}}.com.br/api/catalog_system/pub/products/search, the products are returned with the price from the main price table.

I’ve already tried passing both VtexIdclientAutCookie_vendor and VtexIdclientAutCookie_64c257eb-e3ba-43fe-9ca2-9bc0ffaecb9e in the header, but with no success.

How do I get the API to understand the context of the logged-in user?

Hey, Igor!

These cookies only store the authentication itself. The system responsible for storing user context is VTEX Session, which works with the “vtex_session” and “vtex_segment” cookies.

You can get an overview here: Sessions System Overview

I don’t have direct experience with the headless implementation of this flow, and I’m also not sure whether there’s a guide/documentation specifically aimed at your use case, but I strongly suspect that a simple POST /api/sessions without sending any additional information will be enough both to receive the context cookies and to populate them with the logged-in user (automatically, based on the authentication cookies that will already be traveling in the HTTP request). :smiley:

Hello, @garrucho!

Thank you so much for your reply. I had actually already tried creating a session, but neither of the two cookies was being returned.

The documentation says the body is required, so I was trying to create it by passing the country and a postal code.

Since the customer is from Ecuador and they don’t use postal codes, nothing was being returned. Following your tip, I passed only the country and it came back with the cookies.

I just couldn’t find where I can add the customer’s email to the session data. But reading the link you sent, I think I’ll need to pass the price table in that vtex_segment, correct? So I’ll have to check whether the customer has a special price table and control that in the session.

Or is there a way for me to set the logged-in customer somewhere?

[EDIT]

How do I set the logged-in user?