0

Update My Campaign

by
Published Apr 8, 2025

Update a campaign's properties by `campaignId`. **Please note:** only sample messages are editable.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Update My Campaign
7
 * Update a campaign's properties by `campaignId`. **Please note:** only sample messages are editable.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	campaignId: string,
12
	body: {
13
		resellerId?: string
14
		sample1?: string
15
		sample2?: string
16
		sample3?: string
17
		sample4?: string
18
		sample5?: string
19
		messageFlow?: string
20
		helpMessage?: string
21
		autoRenewal?: false | true
22
		webhookURL?: string
23
		webhookFailoverURL?: string
24
	}
25
) {
26
	const url = new URL(`https://api.telnyx.com/v2/campaign/${campaignId}`)
27

28
	const response = await fetch(url, {
29
		method: 'PUT',
30
		headers: {
31
			'Content-Type': 'application/json',
32
			Authorization: 'Bearer ' + auth.apiKey
33
		},
34
		body: JSON.stringify(body)
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.json()
41
}
42