
You can make requests for:
- results of a [campaign created in the Synerise Portal](/docs/ai-hub/recommendations-v2/creating-recommendation-campaign).  
  With this option, you can create a campaign with filters instead of defining them for each request. You can still tweak filters when making the request. This is the most commonly used method.
- recommendations served [by a recommendation model](#requests-to-a-model) without creating a campaign.  
  With this option, you can make requests without preparing a campaign first, but you need to send the settings that are normally part of the campaign.

## Before you begin
- Ensure that the model for the type of recommendations you want to request is enabled in the [settings of an item feed](/docs/settings/configuration/ai-engine-configuration/engine-configuration-for-recommendations#selecting-recommendation-types-and-default-filters).
- You should be familiar with recommendation types and filter types:  
  - [Recommendation types](/docs/ai-hub/recommendations-v2/recommendation-types)
  - [Recommendation filter types](/docs/ai-hub/recommendations-v2/recommendation-filters#filter-types)


## Elements of the request

### Context
Each recommendation is made in context of a Profile. The profile's attributes can be used in filters.


<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

When making requests from a website, you can find the profile's UUID in the `_snrs_uuid` cookie.

</div></div></div>


You can also add item context to your requests, for example when generating complementary purchase recommendations for a product. The context item's attributes can be used in filters.  
In some recommendations, the item context is required. When it's not required, it can still be included in order to use the context item's attributes in filters.

### Address
The domain of the recommendations API depends on your workspace.
- `https://api.synerise.com` for Microsoft Azure EU environment
- `https://api.azu.synerise.com` for Microsoft Azure USA environment
- `https://api.geb.synerise.com` for Google Cloud Platform environment
- If you have a [custom tracking domain](/developers/web/first-party-tracking) configured, use the custom domain (only for requests made from sites which have a [Tracking Code](/developers/web/installation-and-configuration)).  
  
  <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

  With the custom tracking domain, you must [add `/ai` before the endpoint path in addition to changing the domain](/developers/web/first-party-tracking#updating-your-synerise-api-requests).

  </div></div></div>


### Authentication
The requests can be authenticated in the following ways:
- **Recommended method**: With the key from your [tracking code](/developers/web/installation-and-configuration). This tracker key is added to the request in the `token` query parameter.  
    This method is used in most examples in this guide.
- [With a Workspace JWT (Bearer auth) or Basic authentication](/developers/api/api-authorization/workspace-login).  
  
  <div class="admonition admonition-warning"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" /></svg></div><div class="admonition-body"><div class="admonition-content">

  Workspace JWTs and Basic Authentication can be used ONLY FOR SERVER-TO-SERVER communication. DO NOT use them in your mobile applications or websites.

  </div></div></div>


The following examples show the two methods of authentication.

<div class="content-tabs" data-tab-group="tabgrp-3">
<div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-3-0" data-tab-group="tabgrp-3" data-tab-active="true">Tracker key</button><button class="tab-button" data-tab-id="tabgrp-3-1" data-tab-group="tabgrp-3">JWT</button></div>

<div class="tab-panel" data-tab-id="tabgrp-3-0" data-tab-group="tabgrp-3" data-tab-active="true">

This is the recommended method. The tracker key is included in the `token` parameter.

<pre><code class="language-plaintext">curl --location 'https://api.synerise.com/recommendations/v2/recommend/campaigns/DkhvrZoTKthD?token=98A5FC55-0000-0000-0000-98339BDECAE6&amp;clientUUID=cf9e9b57-7776-51bc-b7bc-75cc75abdf59'
                                                                                              &lt;-------------- tracker key -------------&gt;</code></pre>


where:
- `DkhvrZoTKthD` is an example campaign ID.  
    You can also refer to a campaign by its slug.
- `98A5FC55-0000-0000-0000-98339BDECAE6` is an example tracker key.
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID.

</div>

<div class="tab-panel" data-tab-id="tabgrp-3-1" data-tab-group="tabgrp-3">

The JWT is included in the `Authorization` header.  

<pre><code class="language-plaintext">curl --location 'https://api.synerise.com/recommendations/v2/recommend/campaigns/DkhvrZoTKthD?clientUUID=cf9e9b57-7776-51bc-b7bc-75cc75abdf59' \
--header 'Authorization: Bearer eyJhbGciOiJSUzUx.edWIiOiIyYzU2Yjk5NmR...g7ToscgR9au6fQDhbs'</code></pre>


where:
- `DkhvrZoTKthD` is an example campaign ID.  
    You can also refer to a campaign by its slug.
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID.

</div>
</div>



## Making a request

### Campaign results

You can use two HTTP methods:
- GET: elements of the query are passed as query parameters.
    This method is recommended for making requests from a website.  
- POST: elements of the query are passed in the request body.


  <div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

  For details of all the parameters available for these endpoints, see the API Reference:
  - [GET](https://developers.synerise.com/AIRecommendations/AIRecommendations.html#operation/GetRecommendationsByCampaignV2)
  - [POST](https://developers.synerise.com/AIRecommendations/AIRecommendations.html#operation/PostRecommendationsByCampaignV2)

  </div></div></div>


**Examples**:

<div class="content-tabs" data-tab-group="tabgrp-4">
<div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-4-0" data-tab-group="tabgrp-4" data-tab-active="true">GET cURL + context</button><button class="tab-button" data-tab-id="tabgrp-4-1" data-tab-group="tabgrp-4">POST cURL</button><button class="tab-button" data-tab-id="tabgrp-4-2" data-tab-group="tabgrp-4">GET in JS XHR</button></div>

<div class="tab-panel" data-tab-id="tabgrp-4-0" data-tab-group="tabgrp-4" data-tab-active="true">

In GET requests, the item context is sent in the `itemId` attribute. In campaigns which accept multiple items in the context (cart recommendations), send the attribute multiple times. See example:

<pre><code class="language-plaintext">curl --location 'https://api.synerise.com/recommendations/v2/recommend/campaigns/DkhvrZoTKthD?itemId=0196499479257&amp;itemId=0000301448594&amp;itemId=0000301826378&amp;token=98A5FC55-0000-0000-0000-98339BDECAE6&amp;clientUUID=cf9e9b57-7776-51bc-b7bc-75cc75abdf59'</code></pre>


where:
- `DkhvrZoTKthD` is an example campaign ID.  
    You can also refer to a campaign by its slug.
- `itemId=0196499479257&itemId=0000301448594&itemId=0000301826378` are 3 example items for context.   
  The `itemId` parameter must be sent multiple times to include multiple items.  
  If the campaign doesn't require an item context and you don't want to use it in filters, skip the `itemId` parameter entirely.
- `98A5FC55-0000-0000-0000-98339BDECAE6` is an example tracker key.
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID.

</div>

<div class="tab-panel" data-tab-id="tabgrp-4-1" data-tab-group="tabgrp-4">

<pre><code class="language-LANG">curl --location 'https://api.synerise.com/recommendations/v2/recommend/campaigns?token=98A5FC55-0000-0000-0000-98339BDECAE6' \
--header 'Content-Type: application/json' \
--data '{
    "clientUUID": "cf9e9b57-7776-51bc-b7bc-75cc75abdf59",
    "campaignId": "DkhvrZoTKthD"
}'</code></pre>


where:
- `DkhvrZoTKthD` is an example campaign ID.  
    You can also refer to a campaign by its slug.
- `98A5FC55-0000-0000-0000-98339BDECAE6` is an example tracker key.
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID.

</div>

<div class="tab-panel" data-tab-id="tabgrp-4-2" data-tab-group="tabgrp-4">

This example shows an XHR request with error handling.

<pre><code class="language-javascript">var xhr = new XMLHttpRequest();

// Add an event listener for 'readystatechange' to handle the response
xhr.addEventListener("readystatechange", function() {
  if(this.readyState === XMLHttpRequest.DONE) {
    if (this.status &gt;= 200 &amp;&amp; this.status &lt; 300) {
      // Successful response
      console.log(this.responseText);
    } else {
      // Handle errors
      console.error('Request failed with status:', this.status, 'and response:', this.responseText);
    }
  }
});

// Open a GET request
xhr.open("GET", "https://api.synerise.com/recommendations/v2/recommend/campaigns/DkhvrZoTKthD?token=98A5FC55-0000-0000-0000-98339BDECAE6&amp;clientUUID=cf9e9b57-7776-51bc-b7bc-75cc75abdf59", true);

// Send the request
xhr.send();</code></pre>


where:
- `DkhvrZoTKthD` is an example campaign ID.  
    You can also refer to a campaign by its slug.
- `98A5FC55-0000-0000-0000-98339BDECAE6` is an example tracker key.
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID.

</div>
</div>


### Requests to a model

Instead of getting the results of a recommendation campaign, you can make ad-hoc requests to recommendation models.

In this case, each model has separate endpoints (see [API Reference](https://developers.synerise.com/AIRecommendations/AIRecommendations.html#tag/Recommendations) for a list).


<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

- In these requests, you can pass a `campaignId` parameter. This parameter is added as `utm_campaign` to the links in the recommendation response for use in Decision Hub. It doesn't need to point to any existing recommendation campaign.
- Some recommendation types require additional information, for example the "Recent interactions" model needs an aggregate that defines the interactions to take into account. For details, see the API reference of a particular recommendation type.

</div></div></div>


**Examples**:

<div class="content-tabs" data-tab-group="tabgrp-5">
<div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-5-0" data-tab-group="tabgrp-5" data-tab-active="true">GET personalized</button><button class="tab-button" data-tab-id="tabgrp-5-1" data-tab-group="tabgrp-5">GET cart recommendation</button></div>

<div class="tab-panel" data-tab-id="tabgrp-5-0" data-tab-group="tabgrp-5" data-tab-active="true">

This request fetches a personalized recommendation without any item context or filters.

<pre><code class="language-LANG">curl --location 'https://api.synerise.com/recommendations/v2/recommend/items/users/cf9e9b57-7776-51bc-b7bc-75cc75abdf59?token=98A5FC55-0000-0000-0000-98339BDECAE6'</code></pre>


where:
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID
- `98A5FC55-0000-0000-0000-98339BDECAE6` is an example tracker key


For more details, see [API Reference](https://developers.synerise.com/AIRecommendations/AIRecommendations.html#operation/RecommendForUserV2)

</div>

<div class="tab-panel" data-tab-id="tabgrp-5-1" data-tab-group="tabgrp-5">

This request fetches a recommendation of complementary items for a cart. It lists two items (items in the cart) as the context and explicitly declares the catalog (if not declared, the catalog name is `default`)


<pre><code class="language-LANG">curl --location 'https://api.synerise.com/recommendations/v2/recommend/items/complementary?clientUuid=cf9e9b57-7776-51bc-b7bc-75cc75abdf59&amp;itemId=0000300395769&amp;itemId=0000323544569&amp;itemCatalogId=shoestore&amp;token=98A5FC55-0000-0000-0000-98339BDECAE6&amp;'</code></pre>


where:
- `cf9e9b57-7776-51bc-b7bc-75cc75abdf59` is an example profile UUID
- `itemId=0000300395769&itemId=0000323544569` are 2 example items for context (items in the cart)  
  The `itemId` parameter must be sent multiple times to include multiple items.
- `shoestore` is an example item catalog ID  
  If the `itemCatalogId` parameter isn't included, it defaults to `default`
- `98A5FC55-0000-0000-0000-98339BDECAE6` is an example tracker key

For more details, see [API Reference](https://developers.synerise.com/AIRecommendations/AIRecommendations.html#operation/ComplementItems)

</div>
</div>


## Learn more

A comprehensive list of all endpoints, settings, and parameters is available in the [API Reference](https://developers.synerise.com/AIRecommendations/AIRecommendations.html#tag/Recommendations).

