Edits history of script submission #13943 for ' Update an existing workspace (xata)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xata = {
    	apiKey: string
    }
    /**
     * Update an existing workspace
     * Update workspace info
     */
    export async function main(
    	auth: Xata,
    	workspace_id: string,
    	body: { name: string; slug?: string }
    ) {
    	const url = new URL(`https://api.xata.io/workspaces/${workspace_id}`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		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 428 days ago