0

Create shipment

by
Published Apr 8, 2025

**⚠️ We no longer recommend implementing the Shipments API.

Script mollie Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Mollie = {
3
  token: string;
4
};
5
/**
6
 * Create shipment
7
 * **⚠️ We no longer recommend implementing the Shipments API.
8
 */
9
export async function main(
10
  auth: Mollie,
11
  orderId: string,
12
  body: {
13
    resource?: string;
14
    id?: string;
15
    mode?: string;
16
    lines?: {
17
      resource?: string;
18
      id?: string;
19
      type?: string;
20
      name?: string;
21
      quantity?: number;
22
      amount?: { currency: string; value: string };
23
      unitPrice?: { currency: string; value: string };
24
      totalAmount?: { currency: string; value: string };
25
      vatRate?: string;
26
      vatAmount?: { currency: string; value: string };
27
      sku?: string;
28
      status?: string;
29
      orderId?: string;
30
      createdAt?: string;
31
    }[];
32
    tracking?: { carrier?: string; code?: string; url?: string };
33
    orderId?: string;
34
    createdAt?: string;
35
    _links?: {
36
      self?: { href?: string; type?: string };
37
      order?: { href?: string; type?: string };
38
      documentation?: { href?: string; type?: string };
39
    };
40
  },
41
) {
42
  const url = new URL(`https://api.mollie.com/v2/orders/${orderId}/shipments`);
43

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