Edits history of script submission #18605 for ' Create service preview (image-backed) (render)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Render = {
    	apiKey: string
    }
    /**
     * Create service preview (image-backed)
     * Create a preview instance for an image-backed service. The preview uses the settings of the base service (referenced by `serviceId`), except settings overridden via provided parameters.
    
    View all active previews from your service's Previews tab in the Render Dashboard.
    
    Note that you can't create previews for Git-backed services using the Render API.
    
     */
    export async function main(
    	auth: Render,
    	serviceId: string,
    	body: {
    		imagePath: string
    		name?: string
    		plan?:
    			| 'starter'
    			| 'starter_plus'
    			| 'standard'
    			| 'standard_plus'
    			| 'pro'
    			| 'pro_plus'
    			| 'pro_max'
    			| 'pro_ultra'
    			| 'free'
    			| 'custom'
    	}
    ) {
    	const url = new URL(`https://api.render.com/v1/services/${serviceId}/preview`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago