1 | |
2 | type Phrase = { |
3 | token: string |
4 | baseUrl: string |
5 | } |
6 | |
7 | * List properties |
8 | * List all custom metadata properties for an account. |
9 |
|
10 | This endpoint is only available to accounts with advanced plans or above. |
11 |
|
12 | */ |
13 | export async function main( |
14 | auth: Phrase, |
15 | account_id: string, |
16 | data_type: |
17 | | 'boolean' |
18 | | 'date' |
19 | | 'link' |
20 | | 'multi_select' |
21 | | 'number' |
22 | | 'single_select' |
23 | | 'string' |
24 | | 'text' |
25 | | undefined, |
26 | project_id: string | undefined, |
27 | page: string | undefined, |
28 | per_page: string | undefined, |
29 | q: string | undefined, |
30 | sort: string | undefined, |
31 | order: string | undefined |
32 | ) { |
33 | const url = new URL(`${auth.baseUrl}/accounts/${account_id}/custom_metadata/properties`) |
34 | for (const [k, v] of [ |
35 | ['data_type', data_type], |
36 | ['project_id', project_id], |
37 | ['page', page], |
38 | ['per_page', per_page], |
39 | ['q', q], |
40 | ['sort', sort], |
41 | ['order', order] |
42 | ]) { |
43 | if (v !== undefined && v !== '' && k !== undefined) { |
44 | url.searchParams.append(k, v) |
45 | } |
46 | } |
47 | const response = await fetch(url, { |
48 | method: 'GET', |
49 | headers: { |
50 | Authorization: 'ApiToken ' + auth.token |
51 | }, |
52 | body: undefined |
53 | }) |
54 | if (!response.ok) { |
55 | const text = await response.text() |
56 | throw new Error(`${response.status} ${text}`) |
57 | } |
58 | return await response.json() |
59 | } |
60 |
|