//native
type Adhook = {
token: string
}
export async function main(
auth: Adhook,
id: string,
skip: string | undefined,
limit: string | undefined,
sortBy: string | undefined,
sortDirection: string | undefined,
start: string | undefined,
end: string | undefined,
fetchMode: 'AGGREGATED' | 'DAILY' | undefined,
statusFilter: 'ALL' | 'ACTIVE' | undefined,
adhookToken: string
) {
const url = new URL(`https://app.adhook.io/v1/promotions/${id}/adStatistic`)
for (const [k, v] of [
['skip', skip],
['limit', limit],
['sortBy', sortBy],
['sortDirection', sortDirection],
['start', start],
['end', end],
['fetchMode', fetchMode],
['statusFilter', statusFilter]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
adhookToken: adhookToken,
Authorization: `Bearer ${auth.token}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 16 days ago