1 | |
2 | type Pinterest = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List feeds |
7 | * Fetch feeds owned by the "operation user_account". |
8 | */ |
9 | export async function main( |
10 | auth: Pinterest, |
11 | bookmark: string | undefined, |
12 | page_size: string | undefined, |
13 | catalog_id: string | undefined, |
14 | ad_account_id: string | undefined, |
15 | ) { |
16 | const url = new URL(`https://api.pinterest.com/v5/catalogs/feeds`); |
17 | for (const [k, v] of [ |
18 | ["bookmark", bookmark], |
19 | ["page_size", page_size], |
20 | ["catalog_id", catalog_id], |
21 | ["ad_account_id", ad_account_id], |
22 | ]) { |
23 | if (v !== undefined && v !== "" && k !== undefined) { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "GET", |
29 | headers: { |
30 | Authorization: "Bearer " + auth.token, |
31 | }, |
32 | body: undefined, |
33 | }); |
34 | if (!response.ok) { |
35 | const text = await response.text(); |
36 | throw new Error(`${response.status} ${text}`); |
37 | } |
38 | return await response.json(); |
39 | } |
40 |
|