0

Assign/Update member asset permissions

by
Published Dec 20, 2024

Grant multiple members access to assets and/or update multiple member's exisiting permissions to an asset. Note: Not all listed permissions are applicable to each asset type. For example, PROFILE_PUBLISHER would not be applicable to an asset of type AD_ACCOUNT. The permission level PROFILE_PUBLISHER is only available to an asset of the type PROFILE.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Assign/Update member asset permissions
7
 * Grant multiple members access to assets and/or update multiple member's exisiting permissions to an asset.
8
Note: Not all listed permissions are applicable to each asset type. For example, PROFILE_PUBLISHER would not be applicable to an asset of type AD_ACCOUNT. The permission level PROFILE_PUBLISHER is only available to an asset of the type PROFILE.
9

10
 */
11
export async function main(
12
  auth: Pinterest,
13
  business_id: string,
14
  body: {
15
    accesses: {
16
      asset_id: string;
17
      member_id: string;
18
      permissions:
19
        | "ADMIN"
20
        | "ANALYST"
21
        | "FINANCE_MANAGER"
22
        | "AUDIENCE_MANAGER"
23
        | "CAMPAIGN_MANAGER"
24
        | "CATALOGS_MANAGER"
25
        | "PROFILE_PUBLISHER"[];
26
    }[];
27
  },
28
) {
29
  const url = new URL(
30
    `https://api.pinterest.com/v5/businesses/${business_id}/members/assets/access`,
31
  );
32

33
  const response = await fetch(url, {
34
    method: "PATCH",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47