Edits history of script submission #13951 for ' Update workspace member role (xata)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xata = {
    	apiKey: string
    }
    /**
     * Update workspace member role
     * Update a workspace member role. Workspaces must always have at least one owner, so this operation will fail if trying to remove owner role from the last owner in the workspace.
    
     */
    export async function main(
    	auth: Xata,
    	workspace_id: string,
    	user_id: string,
    	body: { role: 'owner' | 'maintainer' }
    ) {
    	const url = new URL(`https://api.xata.io/workspaces/${workspace_id}/members/${user_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.text()
    }
    

    Submitted by hugo697 428 days ago