0

Update service

by
Published Oct 17, 2025

Update the service with the provided ID.

Script render Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Render = {
3
	apiKey: string
4
}
5
/**
6
 * Update service
7
 * Update the service with the provided ID.
8

9
 */
10
export async function main(
11
	auth: Render,
12
	serviceId: string,
13
	body: {
14
		autoDeploy?: 'yes' | 'no'
15
		repo?: string
16
		branch?: string
17
		image?: {
18
			ownerId: string
19
			registryCredentialId?: string
20
			imagePath: string
21
		}
22
		name?: string
23
		buildFilter?: { paths: string[]; ignoredPaths: string[] }
24
		rootDir?: string
25
		serviceDetails?:
26
			| {
27
					buildCommand?: string
28
					publishPath?: string
29
					pullRequestPreviewsEnabled?: 'yes' | 'no'
30
					previews?: { generation?: 'off' | 'manual' | 'automatic' }
31
					renderSubdomainPolicy?: 'enabled' | 'disabled'
32
			  }
33
			| {
34
					envSpecificDetails?:
35
						| {
36
								dockerCommand?: string
37
								dockerContext?: string
38
								dockerfilePath?: string
39
								registryCredentialId?: string
40
						  }
41
						| { buildCommand?: string; startCommand?: string }
42
					healthCheckPath?: string
43
					maintenanceMode?: { enabled: false | true; uri: string }
44
					plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra'
45
					preDeployCommand?: string
46
					pullRequestPreviewsEnabled?: 'yes' | 'no'
47
					previews?: { generation?: 'off' | 'manual' | 'automatic' }
48
					runtime?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
49
					maxShutdownDelaySeconds?: number
50
					renderSubdomainPolicy?: 'enabled' | 'disabled'
51
			  }
52
			| {
53
					envSpecificDetails?:
54
						| {
55
								dockerCommand?: string
56
								dockerContext?: string
57
								dockerfilePath?: string
58
								registryCredentialId?: string
59
						  }
60
						| { buildCommand?: string; startCommand?: string }
61
					plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra'
62
					preDeployCommand?: string
63
					pullRequestPreviewsEnabled?: 'yes' | 'no'
64
					previews?: { generation?: 'off' | 'manual' | 'automatic' }
65
					runtime?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
66
					maxShutdownDelaySeconds?: number
67
			  }
68
			| {
69
					envSpecificDetails?:
70
						| {
71
								dockerCommand?: string
72
								dockerContext?: string
73
								dockerfilePath?: string
74
								registryCredentialId?: string
75
						  }
76
						| { buildCommand?: string; startCommand?: string }
77
					plan?: 'starter' | 'standard' | 'pro' | 'pro_plus' | 'pro_max' | 'pro_ultra'
78
					schedule?: string
79
					runtime?: 'docker' | 'elixir' | 'go' | 'node' | 'python' | 'ruby' | 'rust' | 'image'
80
			  }
81
	}
82
) {
83
	const url = new URL(`https://api.render.com/v1/services/${serviceId}`)
84

85
	const response = await fetch(url, {
86
		method: 'PATCH',
87
		headers: {
88
			'Content-Type': 'application/json',
89
			Authorization: 'Bearer ' + auth.apiKey
90
		},
91
		body: JSON.stringify(body)
92
	})
93
	if (!response.ok) {
94
		const text = await response.text()
95
		throw new Error(`${response.status} ${text}`)
96
	}
97
	return await response.json()
98
}
99