Edits history of script submission #13235 for ' Get Tasks by Status (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Get Tasks by Status
     * Retrieve tasks for the user that are either `queued`, `processing`, `failed`, `success` or `partial_success` based on the query string. Defaults to `queued` and `processing`.
     */
    export async function main(auth: Telnyx, status: string | undefined) {
    	const url = new URL(`https://api.telnyx.com/v2/ai/embeddings`)
    	for (const [k, v] of [['status', status]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + 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 428 days ago