//native
type Adhook = {
token: string
}
export async function main(
auth: Adhook,
accessToken: string | undefined,
filter: string | undefined,
start: string | undefined,
end: string | undefined,
subtenantId: string | undefined,
groupId: string | undefined,
tagIds: string | undefined,
topicIds: string | undefined,
channels: string | undefined,
promotionStatus:
| 'ALL'
| 'DRAFT'
| 'PLANNED'
| 'IN_PROGRESS'
| 'STOPPED'
| 'IN_REVIEW'
| 'COMPLETED'
| undefined,
promotionType:
| 'ALL'
| 'TRAFFIC'
| 'CONVERSIONS'
| 'RETARGETING'
| 'SHOPPING'
| 'APP'
| 'ENGAGEMENT'
| 'VIDEO_VIEWS'
| 'CALLS'
| 'REACH'
| 'FOLLOWERS'
| 'PROFILE_VIEWS'
| 'LEADS'
| 'PERFORMANCE_MAX'
| undefined,
orderKey: string | undefined,
reverseOrder: string | undefined
) {
const url = new URL(`https://app.adhook.io/v1/promotions/export/xlsx`)
for (const [k, v] of [
['accessToken', accessToken],
['filter', filter],
['start', start],
['end', end],
['subtenantId', subtenantId],
['groupId', groupId],
['tagIds', tagIds],
['topicIds', topicIds],
['channels', channels],
['promotionStatus', promotionStatus],
['promotionType', promotionType],
['orderKey', orderKey],
['reverseOrder', reverseOrder]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${auth.token}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
Submitted by hugo697 16 days ago