Edits history of script submission #20961 for ' Get List Companies (their_stack)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type TheirStack = {
    	apiKey: string
    }
    /**
     * Get List Companies
     *
     */
    export async function main(
    	auth: TheirStack,
    	list_id: string,
    	order_by: 'revealed_at' | 'name' | undefined,
    	order_direction: 'asc' | 'desc' | undefined,
    	company_name_partial: string | undefined,
    	limit: string | undefined,
    	page: string | undefined,
    	offset: string | undefined
    ) {
    	const url = new URL(`https://api.theirstack.com/v0/company_lists/${list_id}/companies`)
    	for (const [k, v] of [
    		['order_by', order_by],
    		['order_direction', order_direction],
    		['company_name_partial', company_name_partial],
    		['limit', limit],
    		['page', page],
    		['offset', offset]
    	]) {
    		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 235 days ago