//native
type Mollie = {
token: string;
};
/**
* Create shipment
* **⚠️ We no longer recommend implementing the Shipments API.
*/
export async function main(
auth: Mollie,
orderId: string,
body: {
resource?: string;
id?: string;
mode?: string;
lines?: {
resource?: string;
id?: string;
type?: string;
name?: string;
quantity?: number;
amount?: { currency: string; value: string };
unitPrice?: { currency: string; value: string };
totalAmount?: { currency: string; value: string };
vatRate?: string;
vatAmount?: { currency: string; value: string };
sku?: string;
status?: string;
orderId?: string;
createdAt?: string;
}[];
tracking?: { carrier?: string; code?: string; url?: string };
orderId?: string;
createdAt?: string;
_links?: {
self?: { href?: string; type?: string };
order?: { href?: string; type?: string };
documentation?: { href?: string; type?: string };
};
},
) {
const url = new URL(`https://api.mollie.com/v2/orders/${orderId}/shipments`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago