//native
type Pinterest = {
token: string;
};
/**
* Create campaigns
* Create multiple new campaigns.
*/
export async function main(
auth: Pinterest,
ad_account_id: string,
body: {
ad_account_id?: string;
name?: string;
status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT";
lifetime_spend_cap?: number;
daily_spend_cap?: number;
order_line_id?: string;
tracking_urls?: {
impression?: string[];
click?: string[];
engagement?: string[];
buyable_button?: string[];
audience_verification?: string[];
};
start_time?: number;
end_time?: number;
is_flexible_daily_budgets?: false | true;
} & {
default_ad_group_budget_in_micro_currency?: number;
is_automated_campaign?: false | true;
} & {
is_flexible_daily_budgets?: false | true;
is_automated_campaign?: false | true;
status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT";
objective_type:
| "AWARENESS"
| "CONSIDERATION"
| "VIDEO_VIEW"
| "WEB_CONVERSION"
| "CATALOG_SALES"
| "WEB_SESSIONS"
| "VIDEO_COMPLETION";
}[],
) {
const url = new URL(
`https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/campaigns`,
);
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