0

Replace header rules

by
Published Oct 17, 2025

Replace all header rules for a particular service with the provided list. **This deletes all existing header rules for the service that aren't included in the request.**

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Replace header rules
7
 * Replace all header rules for a particular service with the provided list.
8

9
**This deletes all existing header rules for the service that aren't included in the request.**
10

11
 */
12
export async function main(
13
	auth: Render,
14
	serviceId: string,
15
	body: { path: string; name: string; value: string }[]
16
) {
17
	const url = new URL(`https://api.render.com/v1/services/${serviceId}/headers`)
18

19
	const response = await fetch(url, {
20
		method: 'PUT',
21
		headers: {
22
			'Content-Type': 'application/json',
23
			Authorization: 'Bearer ' + auth.apiKey
24
		},
25
		body: JSON.stringify(body)
26
	})
27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31
	return await response.json()
32
}
33