Edits history of script submission #12700 for ' Restart a compute endpoint (neondb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Neondb = {
    	apiKey: string
    }
    /**
     * Restart a compute endpoint
     * Restart the specified compute endpoint: suspend immediately followed by start operations.
    You can obtain a `project_id` by listing the projects for your Neon account.
    You can obtain an `endpoint_id` by listing your project's compute endpoints.
    An `endpoint_id` has an `ep-` prefix.
    For information about compute endpoints, see [Manage computes](https://neon.tech/docs/manage/endpoints/).
    
     */
    export async function main(auth: Neondb, project_id: string, endpoint_id: string) {
    	const url = new URL(
    		`https://console.neon.tech/api/v2/projects/${project_id}/endpoints/${endpoint_id}/restart`
    	)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago