0

List Shared Campaigns

by
Published Apr 8, 2025

Retrieve all partner campaigns you have shared to Telnyx in a paginated fashion. This endpoint is currently limited to only returning shared campaigns that Telnyx has accepted. In other words, shared but pending campaigns are currently omitted from the response from this endpoint.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * List Shared Campaigns
7
 * Retrieve all partner campaigns you have shared to Telnyx in a paginated fashion.
8

9
This endpoint is currently limited to only returning shared campaigns that Telnyx has accepted. In other words, shared but pending campaigns are currently omitted from the response from this endpoint.
10
 */
11
export async function main(
12
	auth: Telnyx,
13
	page: string | undefined,
14
	recordsPerPage: string | undefined,
15
	sort:
16
		| 'assignedPhoneNumbersCount'
17
		| '-assignedPhoneNumbersCount'
18
		| 'brandDisplayName'
19
		| '-brandDisplayName'
20
		| 'tcrBrandId'
21
		| '-tcrBranId'
22
		| 'tcrCampaignId'
23
		| '-tcrCampaignId'
24
		| 'createdAt'
25
		| '-createdAt'
26
		| 'campaignStatus'
27
		| '-campaignStatus'
28
		| undefined
29
) {
30
	const url = new URL(`https://api.telnyx.com/v2/partner_campaigns`)
31
	for (const [k, v] of [
32
		['page', page],
33
		['recordsPerPage', recordsPerPage],
34
		['sort', sort]
35
	]) {
36
		if (v !== undefined && v !== '' && k !== undefined) {
37
			url.searchParams.append(k, v)
38
		}
39
	}
40
	const response = await fetch(url, {
41
		method: 'GET',
42
		headers: {
43
			Authorization: 'Bearer ' + auth.apiKey
44
		},
45
		body: undefined
46
	})
47
	if (!response.ok) {
48
		const text = await response.text()
49
		throw new Error(`${response.status} ${text}`)
50
	}
51
	return await response.json()
52
}
53