0

Verify website

by
Published Dec 20, 2024

Verify a website as a signed-in 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
 * Verify website
7
 * Verify a website as a signed-in user.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  ad_account_id: string | undefined,
12
  body: {
13
    website?: string;
14
    verification_method?: "FILENAME" | "METATAG" | "DNSTXT";
15
  },
16
) {
17
  const url = new URL(`https://api.pinterest.com/v5/user_account/websites`);
18
  for (const [k, v] of [["ad_account_id", ad_account_id]]) {
19
    if (v !== undefined && v !== "" && k !== undefined) {
20
      url.searchParams.append(k, v);
21
    }
22
  }
23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      "Content-Type": "application/json",
27
      Authorization: "Bearer " + auth.token,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37