1 | type Datocms = { |
2 | apiKey: string |
3 | } |
4 |
|
5 | export async function main(resource: Datocms, recordId: string) { |
6 | const endpoint = `https://site-api.datocms.com/items/${recordId}/duplicate` |
7 |
|
8 | const response = await fetch(endpoint, { |
9 | method: 'POST', |
10 | headers: { |
11 | Authorization: `Bearer ${resource.apiKey}`, |
12 | Accept: 'application/json', |
13 | 'X-Api-Version': '3' |
14 | } |
15 | }) |
16 |
|
17 | if (!response.ok) { |
18 | throw new Error(`HTTP error! status: ${response.status}`) |
19 | } |
20 |
|
21 | const data = await response.json() |
22 |
|
23 | return data |
24 | } |
25 |
|