//native
type Adhook = {
token: string
}
export async function main(
auth: Adhook,
promotionStatus:
| 'ALL'
| 'DRAFT'
| 'PLANNED'
| 'IN_PROGRESS'
| 'STOPPED'
| 'IN_REVIEW'
| 'COMPLETED'
| undefined,
start: string | undefined,
end: string | undefined,
subtenantId: string | undefined,
groupId: string | undefined,
tagIds: string | undefined,
topicIds: string | undefined,
channels: string | undefined,
adhookToken: string
) {
const url = new URL(`https://app.adhook.io/v1/promotions/calendar`)
for (const [k, v] of [
['promotionStatus', promotionStatus],
['start', start],
['end', end],
['subtenantId', subtenantId],
['groupId', groupId],
['tagIds', tagIds],
['topicIds', topicIds],
['channels', channels]
]) {
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 42 days ago