Edits history of script submission #22188 for ' Deletes an API key (zuplo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zuplo = {
    	apiKey: string
    }
    /**
     * Deletes an API key
     * Deletes an API key for this consumer.
     */
    export async function main(
    	auth: Zuplo,
    	accountName: string,
    	bucketName: string,
    	consumerName: string,
    	keyId: string,
    	tag: string | undefined
    ) {
    	const url = new URL(
    		`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}/keys/${keyId}`
    	)
    	for (const [k, v] of [['tag', tag]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'DELETE',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 235 days ago