//native
type Pinterest = {
token: string;
};
/**
* Redeem ad credits
* Redeem ads credit on behalf of the ad account id and apply it towards billing.
This endpoint might not be available to all apps. Learn more.
*/
export async function main(
auth: Pinterest,
ad_account_id: string,
body: { offerCodeHash: string; validateOnly: false | true },
) {
const url = new URL(
`https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ads_credit/redeem`,
);
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