0

Redeem ad credits

by
Published Dec 20, 2024

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.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Redeem ad credits
7
 * Redeem ads credit on behalf of the ad account id and apply it towards billing.
8

9
This endpoint might not be available to all apps. Learn more.
10
 */
11
export async function main(
12
  auth: Pinterest,
13
  ad_account_id: string,
14
  body: { offerCodeHash: string; validateOnly: false | true },
15
) {
16
  const url = new URL(
17
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ads_credit/redeem`,
18
  );
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      "Content-Type": "application/json",
24
      Authorization: "Bearer " + auth.token,
25
    },
26
    body: JSON.stringify(body),
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34