0

List custom domains

by
Published Oct 17, 2025

List a particular service's custom domains that match the provided filters. If no filters are provided, all custom domains for the service are returned.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * List custom domains
7
 * List a particular service's custom domains that match the provided filters. If no filters are provided, all custom domains for the service are returned.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	serviceId: string,
13
	cursor: string | undefined,
14
	limit: string | undefined,
15
	name: string | undefined,
16
	domainType: 'apex' | 'subdomain' | undefined,
17
	verificationStatus: 'verified' | 'unverified' | undefined,
18
	createdBefore: string | undefined,
19
	createdAfter: string | undefined
20
) {
21
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/custom-domains`)
22
	for (const [k, v] of [
23
		['cursor', cursor],
24
		['limit', limit],
25
		['name', name],
26
		['domainType', domainType],
27
		['verificationStatus', verificationStatus],
28
		['createdBefore', createdBefore],
29
		['createdAfter', createdAfter]
30
	]) {
31
		if (v !== undefined && v !== '' && k !== undefined) {
32
			url.searchParams.append(k, v)
33
		}
34
	}
35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			Authorization: 'Bearer ' + auth.apiKey
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48