Request ads and render them
Send one ad request per page view and render the ads that come back. Sponsored Display and Sponsored Products use the same endpoint.
Every ad request needs the domain_id, the API key, the placements with their keys, and a session_id. What else you send depends on the page.
POST /server/v2/ads · Full reference
| Page | Add to the request |
|---|---|
| Search results | search (the shopper’s query) and the listed products |
| Category page | category (or your category_id) and the listed products |
| Product page | products, with the viewed product first |
| Homepage | nothing else, unless the page lists products |
Pick a page below. The sample updates in your chosen language.
- cURL
- Node.js
- Python
curl --request POST 'https://xxx.edge-stage.gowit.app/server/v2/ads' \
--header 'Authorization: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"domain_id": 1001,
"session_id": "ec07083a-8bf812",
"placements": [
{
"placement_id": 1
}
],
"search": "hiking boots",
"products": [
{
"id": "P30005",
"category": "Outdoor>Footwear>Hiking Sandals"
},
{
"id": "P30003",
"category": "Outdoor>Footwear"
},
{
"id": "P30001",
"category": "Outdoor>Footwear"
}
],
"page_number": 0
}'
const res = await fetch('https://xxx.edge-stage.gowit.app/server/v2/ads', {
method: 'POST',
headers: {
"Authorization": "YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
"domain_id": 1001,
"session_id": "ec07083a-8bf812",
"placements": [
{
"placement_id": 1
}
],
"search": "hiking boots",
"products": [
{
"id": "P30005",
"category": "Outdoor>Footwear>Hiking Sandals"
},
{
"id": "P30003",
"category": "Outdoor>Footwear"
},
{
"id": "P30001",
"category": "Outdoor>Footwear"
}
],
"page_number": 0
}),
})
if (res.status === 204) {
console.log('No content')
} else {
console.log(res.status, await res.text())
}
import requests
url = "https://xxx.edge-stage.gowit.app/server/v2/ads"
headers = {
"Authorization": "YOUR_API_KEY",
"Content-Type": "application/json",
}
payload = {
"domain_id": 1001,
"session_id": "ec07083a-8bf812",
"placements": [
{
"placement_id": 1,
},
],
"search": "hiking boots",
"products": [
{
"id": "P30005",
"category": "Outdoor>Footwear>Hiking Sandals",
},
{
"id": "P30003",
"category": "Outdoor>Footwear",
},
{
"id": "P30001",
"category": "Outdoor>Footwear",
},
],
"page_number": 0,
}
response = requests.request("POST", url, headers=headers, json=payload, timeout=10)
print(response.status_code, response.text)
Request fields
| Field | Type | Required | Description |
|---|---|---|---|
domain_id | integer | Yes | Your domain id: the number of your market on GoWit. GoWit shares it with your host and keys. Stage and production use their own values. |
session_id | string | Yes | The shopper's session id. Keep it stable for the whole attribution window: impressions, clicks and sales are matched to ads by it. |
placements | object[] | Yes | The slots on this page that should be filled. Each is answered in order. |
products | object[] | When listing pages | The products listed organically on the page, in page order, each with its category. GoWit uses them for relevance. On a product detail page put the viewed product first. Leave it out when the page lists no products (e.g. a homepage). |
search | string | When on search pages | The shopper's search query. Drives keyword targeting. |
category | string | When on category pages | The exact category path of the page, e.g. Outdoor>Footwear. |
category_id | string | No | Your own category code, accepted in place of category. When the code is unknown, category is used. |
page_number | integer | No | Results page, starting at 0. Lets ads continue in ranked order on page 2, 3, … Default 0. |
customer | object | No | Shopper context. Every field is optional and a bad value is dropped, never refused. |
Keep session_id stable for the whole attribution window. Sales are matched to ads by it.
Sponsored products response
Show each returned product in its slot, using product_id and seller_ref. product_id is the product’s sku, or its id when no sku was sent. Sale events still name the product by its id.
{
"placements": [
{
"ads": [
{ "ad_id": "AbX3kQ9rT2vLm8...wP4n", "seller_ref": "ADV003", "label": "Sponsored", "position": 1, "product_id": "P30007", "products": null, "redirects": null },
{ "ad_id": "Ac7Hn2sW5xBq1...tR8k", "seller_ref": "ADV002", "label": "Sponsored", "position": 2, "product_id": "P30017", "products": null, "redirects": null }
],
"placement_id": 1
}
],
"response_id": "e5c257b0-d40d-4f02-81b7-b0599eee6db3"
}
Sponsored display response
Build the banner from img_url, its size and its redirect. When HTML creatives are on for your market, an html field comes too; render it when it is there.
{
"placements": [
{
"ads": [
{
"ad_id": "AbX3kQ9rT2vLm8...wP4n",
"seller_ref": "ADV001",
"creative_id": 6438,
"img_url": "https://cdn.example.com/creatives/7f3c/banner-300x250.png",
"label": "Sponsored",
"position": 1,
"products": [{ "sku": "P30001", "name": "Waterproof Hiking Boots", "price": 129.99 }],
"redirect": { "type": "CUSTOM", "url": "https://www.example.com/outdoor" },
"size": "300x250"
}
],
"placement_id": 5
}
],
"response_id": "69cd47e3-ac75-4bc4-b621-2fea4b865f87"
}
A 204 with an empty body means no placement got an ad. A 200 leaves out each placement with no ad. On a 204 or a timeout, keep the slot empty or show your own content.
The ad_id is a sealed token. Send it back in events exactly as it came, without changing it.
Ads are answered within about 200 ms. Set your client timeout close to that and never hold the page for an ad.
Checklist
- An ad request for the sponsored display format returns an ad response. (Retailer)
- An ad request for the sponsored products format returns an ad response. (Retailer)
- Impression counts in the Onsite app rise for the returned ads. (Retailer)