//native
type Pinterest = {
token: string;
};
/**
* Create lead ads subscription
* Create a lead ads webhook subscription.
*/
export async function main(
auth: Pinterest,
ad_account_id: string,
body: {
webhook_url: string;
lead_form_id?: string;
partner_access_token?: string;
partner_refresh_token?: string;
partner_metadata?: { subscriber_key?: string };
},
) {
const url = new URL(
`https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/leads/subscriptions`,
);
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