0

Follow user

by
Published Dec 20, 2024

This endpoint is currently in beta and not available to all apps. Learn more. Use this request, as a signed-in user, to follow another user.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Follow user
7
 * This endpoint is currently in beta and not available to all apps. Learn more.
8

9
Use this request, as a signed-in user, to follow another user.
10
 */
11
export async function main(
12
  auth: Pinterest,
13
  username: string,
14
  body: { auto_follow?: false | true },
15
) {
16
  const url = new URL(
17
    `https://api.pinterest.com/v5/user_account/following/${username}`,
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