1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List Brands |
7 | * This endpoint is used to list all brands associated with your organization. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | page: string | undefined, |
12 | recordsPerPage: string | undefined, |
13 | sort: |
14 | | 'assignedCampaignsCount' |
15 | | '-assignedCampaignsCount' |
16 | | 'brandId' |
17 | | '-brandId' |
18 | | 'createdAt' |
19 | | '-createdAt' |
20 | | 'displayName' |
21 | | '-displayName' |
22 | | 'identityStatus' |
23 | | '-identityStatus' |
24 | | 'status' |
25 | | '-status' |
26 | | 'tcrBrandId' |
27 | | '-tcrBrandId' |
28 | | undefined, |
29 | displayName: string | undefined, |
30 | entityType: string | undefined, |
31 | state: string | undefined, |
32 | country: string | undefined, |
33 | brandId: string | undefined, |
34 | tcrBrandId: string | undefined |
35 | ) { |
36 | const url = new URL(`https://api.telnyx.com/v2/brand`) |
37 | for (const [k, v] of [ |
38 | ['page', page], |
39 | ['recordsPerPage', recordsPerPage], |
40 | ['sort', sort], |
41 | ['displayName', displayName], |
42 | ['entityType', entityType], |
43 | ['state', state], |
44 | ['country', country], |
45 | ['brandId', brandId], |
46 | ['tcrBrandId', tcrBrandId] |
47 | ]) { |
48 | if (v !== undefined && v !== '' && k !== undefined) { |
49 | url.searchParams.append(k, v) |
50 | } |
51 | } |
52 | const response = await fetch(url, { |
53 | method: 'GET', |
54 | headers: { |
55 | Authorization: 'Bearer ' + auth.apiKey |
56 | }, |
57 | body: undefined |
58 | }) |
59 | if (!response.ok) { |
60 | const text = await response.text() |
61 | throw new Error(`${response.status} ${text}`) |
62 | } |
63 | return await response.json() |
64 | } |
65 |
|