//native
type Pinterest = {
token: string;
};
/**
* Create custom audience
* Create a custom audience and find the audiences you want your ads to reach.
*/
export async function main(
auth: Pinterest,
ad_account_id: string,
body: {
ad_account_id?: string;
name?: string;
rule?: {
country?: string;
customer_list_id?: string;
engagement_domain?: string[];
engagement_type?: string;
event?: string;
event_data?: {
currency?:
| "UNK"
| "USD"
| "GBP"
| "CAD"
| "EUR"
| "AUD"
| "NZD"
| "SEK"
| "ILS"
| "CHF"
| "HKD"
| "JPY"
| "SGD"
| "KRW"
| "NOK"
| "DKK"
| "PLN"
| "RON"
| "HUF"
| "CZK"
| "BRL"
| "MXN"
| "ARS"
| "CLP"
| "COP"
| "INR"
| "TRY";
lead_type?: string;
line_items?: {
product_brand?: string;
product_category?: string;
product_id?: number;
product_name?: string;
product_price?: string;
product_quantity?: number;
product_variant?: string;
product_variant_id?: string;
};
order_id?: string;
order_quantity?: number;
page_name?: string;
promo_code?: string;
property?: string;
search_query?: string;
value?: string;
video_title?: string;
};
percentage?: number;
pin_id?: string[];
prefill?: false | true;
retention_days?: number;
seed_id?: string[];
url?: string[];
visitor_source_id?: string;
event_source?: {};
ingestion_source?: {};
engager_type?: number;
campaign_id?: string[];
ad_id?: string[];
objective_type?:
| "AWARENESS"
| "CONSIDERATION"
| "VIDEO_VIEW"
| "WEB_CONVERSION"
| "CATALOG_SALES"
| "WEB_SESSIONS"
| "VIDEO_COMPLETION"[];
ad_account_id?: string;
};
} & {
sharing_type: "CUSTOM" | "SYNDICATED";
data_party: "1p" | "3p";
category?: string;
},
) {
const url = new URL(
`https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/audiences/custom`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago