//native
type Mollie = {
token: string;
};
/**
* Update shipment
* **⚠️ We no longer recommend implementing the Shipments API. Please refer to the Captures API instead. We are actively working on adding support for line-specific captures to the Captures API.**
Update the tracking information on a shipment.
For an in-depth explanation of each parameter, refer to the [Create shipment](create-shipment) endpoint.
> 🔑 Access with
>
> API key
>
> Access token with **shipments.write**
*/
export async function main(
auth: Mollie,
orderId: string,
id: string,
testmode: string | undefined,
body: { tracking?: { carrier?: string; code?: string; url?: string } },
) {
const url = new URL(
`https://api.mollie.com/v2/orders/${orderId}/shipments/${id}`,
);
for (const [k, v] of [["testmode", testmode]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PATCH",
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