0
Get Contact
One script reply has been approved by the moderators Verified

Retrieves an existing contact.

Created by hugo697 76 days ago Viewed 29 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 76 days ago
1
type Campayn = {
2
	apiKey: string
3
}
4

5
export async function main(resource: Campayn, contactId: string) {
6
	const endpoint = `https://campayn.com/api/v1/contacts/${contactId}.json`
7

8
	const response = await fetch(endpoint, {
9
		method: 'GET',
10
		headers: {
11
			Authorization: `TRUEREST apikey=${resource.apiKey}`
12
		}
13
	})
14

15
	if (!response.ok) {
16
		throw new Error(`HTTP error! status: ${response.status}`)
17
	}
18

19
	const data = await response.json()
20

21
	return data
22
}
23