Edits history of script submission #17263 for ' Retrieve a list of all the keys (mezmo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve a list of all the keys
     * Retrieve a list of all the keys for an account. Supported key types include `ingestion` and `service`. Use the `type` parameter to filter which type of keys to retrieve.
     */
    export async function main(auth: RT.Mezmo, _type?: 'ingestion' | 'service' | 'all' | undefined) {
    	const url = new URL(`https://api.mezmo.com/v1/config/keys`)
    	for (const [k, v] of [['type', _type]]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Token ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago