1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | position_id: string, |
9 | identifier_type: 'id' | 'external_id' | undefined, |
10 | body: { external_id?: string; import_id?: string; name?: string } |
11 | ) { |
12 | const url = new URL(`https://motimateapp.com/public_api/positions/${position_id}`) |
13 |
|
14 | for (const [k, v] of [['identifier_type', identifier_type]]) { |
15 | if (v !== undefined && v !== '' && k !== undefined) { |
16 | url.searchParams.append(k, v) |
17 | } |
18 | } |
19 |
|
20 | const response = await fetch(url, { |
21 | method: 'PATCH', |
22 | headers: { |
23 | 'Content-Type': 'application/json', |
24 | Authorization: 'Bearer ' + auth.token |
25 | }, |
26 | body: JSON.stringify(body) |
27 | }) |
28 |
|
29 | if (!response.ok) { |
30 | const text = await response.text() |
31 | throw new Error(`${response.status} ${text}`) |
32 | } |
33 |
|
34 | return await response.json() |
35 | } |
36 |
|