0

Update Document

by
Published Oct 17, 2025

Update a specific document. {lotSku} field is only needed when {kind} is lots.

Script holded Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Holded = {
3
  apiKey: string;
4
};
5
/**
6
 * Update Document
7
 * Update a specific document. {lotSku} field is only needed when {kind} is lots.
8
 */
9
export async function main(
10
  auth: Holded,
11
  docType: string,
12
  documentId: string,
13
  body: {
14
    desc?: string;
15
    notes?: string;
16
    language?: string;
17
    date?: number;
18
    paymentMethod?: string;
19
    warehouseId?: string;
20
    items?: {
21
      name?: string;
22
      desc?: string;
23
      subtotal?: number;
24
      tax?: number;
25
      tags?: string[];
26
      units?: number;
27
      discount?: number;
28
      accountingAccountId?: string;
29
      kind?: string;
30
      sku?: string;
31
      lotSku?: string;
32
      supplied?: string;
33
    }[];
34
    salesChannelId?: string;
35
    expAccountId?: string;
36
    customFields?: { field?: string; value?: string }[];
37
  },
38
) {
39
  const url = new URL(
40
    `https://api.holded.com/api/invoicing/v1/documents/${docType}/${documentId}`,
41
  );
42

43
  const response = await fetch(url, {
44
    method: "PUT",
45
    headers: {
46
      "Content-Type": "application/json",
47
      key: auth.apiKey,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57