400 error when attempting to fulfill line item via API

In the node.js test script below, I am attempting to fulfill the second line item in an order via the Shopify API.
In debugger I am able to see that the order is successfully downloaded, but when

the fulfillment is attempted, I get a 400 error. Ideas?

Error: Response code 400 (Bad Request)

at Request. (c:\nodejs\node_modules\got\dist\source\as-promise\index.js:118:42)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {name: ‘HTTPError’, code: ‘ERR_NON_2XX_3XX_RESPONSE’, timings: {…}, stack: 'HTTPError: Response code 400 (Bad Request)

…ions (node:internal/process/task_queues:95:5)', message: ‘Response code 400 (Bad Request)’, …}

==========================================================================================
const Shopify = require(‘shopify-api-node’);

const shopify = new Shopify({
shopName: ‘xxxx.myshopify.com’,
accessToken:‘xxxx’
});
async function fulfillSecondLineItem(orderId) {
try {
const order = await shopify.order.get(orderId);
// Check if the order has at least two line items
if (order.line_items && order.line_items.length >= 2) {
const secondLineItem = order.line_items[1]; // Get the second line item
// Create a fulfillment for the second line item
const fulfillment = {
order_id: orderId,
line_items: [{ id: secondLineItem.id }] // Fulfill only the second line item
};
// Post the fulfillment to Shopify
const response = await shopify.fulfillment.create(orderId, fulfillment);
console.log(‘Fulfillment created:’, response);
} else {
console.log(‘Order does not have enough line items.’);
}
} catch (error) {
console.error(‘Error:’, error);
}
}

fulfillSecondLineItem(orderId);

I have moved this question to a more appropriate discussion under ‘partners & developers’.