1 | |
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | Origin: string, |
9 | body: { |
10 | id?: string |
11 | createdByUserId?: string |
12 | createdByUserEmail?: string |
13 | type?: |
14 | | 'EMAIL_CAMPAIGN' |
15 | | 'PRINT_CAMPAIGN' |
16 | | 'PRESS_RELEASE' |
17 | | 'INTERNAL_COMMUNICATION' |
18 | | 'OTHER' |
19 | | 'EVENT' |
20 | | 'ONLINE_PLATFORM' |
21 | | 'ADVERTISING' |
22 | | 'BLOG' |
23 | status?: 'CREATED' | 'DELETED' |
24 | tags?: { |
25 | id?: string |
26 | userId?: string |
27 | tenantId?: string |
28 | subtenantId?: string |
29 | text?: string |
30 | color?: string |
31 | }[] |
32 | topics?: { id?: string; name?: string }[] |
33 | tenantId?: string |
34 | subtenantId?: string |
35 | createdAt?: string |
36 | start?: string |
37 | end?: string |
38 | processReviewFeedback?: string |
39 | processReviewFeedbackAnswer?: string |
40 | title?: string |
41 | description?: string |
42 | externalId?: string |
43 | allDay?: false | true |
44 | attachments?: { name?: string; url?: string; fileExtension?: string }[] |
45 | color?: string |
46 | } |
47 | ) { |
48 | const url = new URL(`https://app.adhook.io/v1/customEvents`) |
49 |
|
50 | const response = await fetch(url, { |
51 | method: 'POST', |
52 | headers: { |
53 | Authorization: `Bearer ${auth.token}`, |
54 | Origin: Origin, |
55 | 'Content-Type': 'application/json' |
56 | }, |
57 | body: JSON.stringify(body) |
58 | }) |
59 |
|
60 | if (!response.ok) { |
61 | const text = await response.text() |
62 | throw new Error(`${response.status} ${text}`) |
63 | } |
64 |
|
65 | return await response.json() |
66 | } |
67 |
|