0

Update audience sharing from an ad account to businesses

by
Published Dec 20, 2024

From an ad account, share a specific audience with a business account, or revoke access to a previously shared audience. Only the audience owner account can share the audience. The recipient business account must be in the same business hierarchy as the business owner of the ad account. This endpoint is not 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
 * Update audience sharing from an ad account to businesses
7
 * From an ad account, share a specific audience with a business account, or revoke access to a previously shared audience. Only the audience owner account can share the audience. The recipient business account must be in the same business hierarchy as the business owner of the ad account. This endpoint is not available to all apps.Learn more.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  ad_account_id: string,
12
  body: { audience_id?: string; operation_type?: "SHARE" | "REVOKE" } & {
13
    recipient_business_ids: string[];
14
  },
15
) {
16
  const url = new URL(
17
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/audiences/businesses/shared`,
18
  );
19

20
  const response = await fetch(url, {
21
    method: "PATCH",
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