//native
type TheirStack = {
apiKey: string
}
/**
* Get Saved Searches
* List all the saved searches for the current user
*/
export async function main(
auth: TheirStack,
user_ids: string | undefined,
types: string | undefined,
order_by: 'name' | 'created_at' | 'updated_at' | undefined,
order_direction: 'asc' | 'desc' | undefined
) {
const url = new URL(`https://api.theirstack.com/v0/saved_searches`)
for (const [k, v] of [
['user_ids', user_ids],
['types', types],
['order_by', order_by],
['order_direction', order_direction]
]) {
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