0

Create an invoice adjustment

by
Published Oct 17, 2025

Create an invoice adjustment using this endpoint. For example, you can add a bonus, commission, VAT %, deduction etc. to an invoice. **Token scopes**: `invoice-adjustments:write`, `worker:write`

Script deel Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Create an invoice adjustment
4
 * Create an invoice adjustment using this endpoint. For example, you can add a bonus, commission, VAT %, deduction etc. to an invoice.
5
 **Token scopes**: `invoice-adjustments:write`, `worker:write`
6
 */
7
export async function main(auth: RT.Deel, body: Body, recurring?: string | undefined) {
8
	const url = new URL(`https://api.letsdeel.com/rest/v2/invoice-adjustments`)
9
	for (const [k, v] of [['recurring', recurring]]) {
10
		if (v !== undefined && v !== '') {
11
			url.searchParams.append(k, v)
12
		}
13
	}
14
	const formData = new FormData()
15
	for (const [k, v] of Object.entries(body)) {
16
		if (v !== undefined && v !== '') {
17
			formData.append(k, String(v))
18
		}
19
	}
20
	const response = await fetch(url, {
21
		method: 'POST',
22
		headers: {
23
			'Content-Type': 'application/json',
24
			Authorization: 'Bearer ' + auth.apiKey
25
		},
26
		body: JSON.stringify(body)
27
	})
28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32
	return await response.json()
33
}
34

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

42
export interface Body {
43
	/**
44
	 * Details of invoice adjustment to create.
45
	 */
46
	data: {
47
		/**
48
		 * Type of invoice adjustment.
49
		 */
50
		type:
51
			| 'bonus'
52
			| 'commission'
53
			| 'deduction'
54
			| 'expense'
55
			| 'other'
56
			| 'overtime'
57
			| 'time_off'
58
			| 'vat'
59
		/**
60
		 * Amount to be paid. Must be a positive number.
61
		 */
62
		amount: number
63
		/**
64
		 * Id of a Deel contract.
65
		 */
66
		contract_id: string
67
		/**
68
		 * Description of the adjustment.
69
		 */
70
		description: string
71
		/**
72
		 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
73
		 */
74
		date_submitted: string
75
		/**
76
		 * ID of an existing active payment cycle - required if type is "vat"
77
		 */
78
		paymentCycleId?: number
79
		/**
80
		 * If true, the invoice adjustment will be automatically approved as part of the request.
81
		 */
82
		is_auto_approved?: boolean
83
		/**
84
		 * Id of an existing preset.
85
		 */
86
		hourly_report_preset_id?: string
87
		[k: string]: unknown
88
	}
89
	[k: string]: unknown
90
}
91