const apikey = "TSC_...";
const body = {
bids: [
{
target: {
type: "product",
id: "example-product-coca-cola",
},
triggers: [
{
type: "keyword",
value: {
matchType: "exact",
words: ["soft drink"],
},
},
],
},
],
budget: {
type: "daily",
amount: 10000,
},
campaignType: "autobidding",
isActive: true,
status: "approved",
adFormat: "listing",
name: "An example campaign",
};
try {
const response = await fetch(
"https://api.topsort.com/public/v1/campaign-service/campaigns?vendor_id=demo-vendor",
{
method: "POST",
mode: "cors",
headers: {
Authorization: `Bearer ${apikey}`,
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify(body),
}
);
if (!response.ok) {
console.error("unexpected status: " + response.status);
} else {
console.log("success status: " + response.status);
}
} catch (error) {
console.error(error);
}