0

Create a Milestone

by
Published Oct 17, 2025

Add a new milestone to a specific contract. Milestones represent distinct deliverables or phases in the contract and can include additional details such as attachments. **Token scopes**: `milestones:write`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create a Milestone
4
 * Add a new milestone to a specific contract. Milestones represent distinct deliverables or phases in the contract and can include additional details such as attachments.
5
 **Token scopes**: `milestones:write`
6
 */
7
export async function main(auth: RT.Deel, contract_id: string, body: Body) {
8
	const url = new URL(`https://api.letsdeel.com/rest/v2/contracts/${contract_id}/milestones`)
9

10
	const formData = new FormData()
11
	for (const [k, v] of Object.entries(body)) {
12
		if (v !== undefined && v !== '') {
13
			formData.append(k, String(v))
14
		}
15
	}
16
	const response = await fetch(url, {
17
		method: 'POST',
18
		headers: {
19
			'Content-Type': 'application/json',
20
			Authorization: 'Bearer ' + auth.apiKey
21
		},
22
		body: JSON.stringify(body)
23
	})
24
	if (!response.ok) {
25
		const text = await response.text()
26
		throw new Error(`${response.status} ${text}`)
27
	}
28
	return await response.json()
29
}
30

31
/* eslint-disable */
32
/**
33
 * This file was automatically generated by json-schema-to-typescript.
34
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
35
 * and run json-schema-to-typescript to regenerate this file.
36
 */
37

38
export interface Body {
39
	data: {
40
		/**
41
		 * The title of the milestone.
42
		 */
43
		title: string
44
		amount: string | number
45
		/**
46
		 * A detailed description of the milestone.
47
		 */
48
		description: string
49
		[k: string]: unknown
50
	}
51
	[k: string]: unknown
52
}
53