0

Create a request to access an existing partner's assets.

by
Published Dec 20, 2024

Create a request to access an existing partner's assets with the specified permissions. The request will be sent to the partner for approval. The assets that can be requested are ad accounts and profiles.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Create a request to access an existing partner's assets.
7
 * Create a request to access an existing partner's assets with the specified permissions. The request will be sent to the partner for approval. The assets that can be requested are ad accounts and profiles.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  business_id: string,
12
  body: {
13
    asset_requests: { partner_id: string; asset_id_to_permissions: {} }[];
14
  },
15
) {
16
  const url = new URL(
17
    `https://api.pinterest.com/v5/businesses/${business_id}/requests/assets/access`,
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