Edits history of script submission #9775 for ' Create a user in the current customer account (vectara)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vectara = {
    	apiKey: string
    }
    /**
     * Create a user in the current customer account
     * Create a user for the current customer account.
     */
    export async function main(
    	auth: Vectara,
    	body: {
    		email: string
    		username?: string
    		description?: string
    		api_roles?: 'owner' | 'administrator' | 'billing_administrator' | 'corpus_administrator'[]
    	}
    ) {
    	const url = new URL(`https://api.vectara.io/v2/users`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			'x-api-key': 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 581 days ago