> For the complete documentation index, see [llms.txt](https://docs.discoverist.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.discoverist.ai/reference/api-reference/recently-viewed.md).

# Recently Viewed

## Get Recently Viewed

<mark style="color:green;">`POST`</mark> `https://api.discoverist.ai/recommend/v1/clients/{client_id}/products/recentlyviewed`

Get Recently viewed products. Returns 6 recently viewed products by user.&#x20;

#### Request Body

| Name     | Type   | Description                                          |
| -------- | ------ | ---------------------------------------------------- |
| user\_id | string | unique user identifer for each user on your website. |

{% tabs %}
{% tab title="200 Get Recently Viewed" %}

```javascript
{
    "results": [
        {
            "id": 7951785263271,
            "name": "Airdog V5 Car Air Purifier",
            "url": "https://cdn.shopify.com/s/files/1/0635/0959/4279/products/car-purifier-1.webp?v=1709604067",
            "price": 99.0,
            "handle": "airdog-v5-car-air-purifier",
            "options": [
                {
                    "name": "Title",
                    "position": 1,
                    "values": [
                        "Default Title"
                    ]
                }
            ],
            "sizes": "Default",
            "variants": [
                {
                    "id": 44802403074215,
                    "product_id": 7951785263271,
                    "title": "Default Title",
                    "price": "99.00",
                    "inventory_policy": "continue",
                    "compare_at_price": "199.00",
                    "option1": "Default Title",
                    "option2": null,
                    "option3": null
                }
            ],
            "images": [],
            "age_group": ""
        },
       "..."
    ]
}
```

{% endtab %}

{% tab title="Error" %}

```
{
    "error": "No matching document found."
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="curl" %}

```javascript
curl --location 'https://api.discoverist.ai/recommend/v1/clients/{YOUR_CLIENT_ID}/products/recentlyviewed' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
    "product_id": "7951758721191",
    "user_id": "XYZ"
}'
```

{% endtab %}

{% tab title="Java Script" %}

```javascript
const apiKey = process.env.REACT_APP_API_KEY || 'YOUR_API_KEY'; // Replace with your actual API key (consider environment variables)
const clientId = 'YOUR_CLIENT_ID'; // Replace with your actual client ID
const url = `https://api.discoverist.ai/recommend/v1/clients/${clientId}/products/recentlyviewed`;
const headers = {
    'accept': 'application/json',
    'x-api-key': apiKey,
  };
const data = {
  product_id: "242424242",
  user_id: "XYZ"
};
const response = await fetch(url, {
      method: 'GET',
      headers,
      body: JSON.stringify(data),  
    });
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import os
api_key = os.environ.get("YOUR_API_KEY")
client_id = "YOUR_CLIENT_ID"  # Replace with your actual client ID
headers = {
    'accept': 'application/json',
    'x-api-key': YOUR_API_KEY,
}
data = {
    "user_id": "XYZ"
}
url = "https://api.discoverist.ai/recommend/v1/clients/" + client_id + "/products/recentlyviewed"
response = requests.get(url, headers=headers, json=data, verify=False)
```

{% endtab %}
{% endtabs %}
