//native
type TheirStack = {
apiKey: string
}
/**
* Get Companies Per Company Country Code
* This endpoint will return all country codes and the number of companies whose HQ is in that country.
Calls to this endpoint don't cost you credits.
*/
export async function main(
auth: TheirStack,
country: string | undefined,
page: string | undefined,
limit: string | undefined
) {
const url = new URL(`https://api.theirstack.com/v0/catalog/companies_per_company_country_code`)
for (const [k, v] of [
['country', country],
['page', page],
['limit', limit]
]) {
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