Not able to create fulfillment order problem using npm shopify-api-node

Hi everyone,

I have just started with Shopify. I am trying to create a fulfilment using this code

import Shopify from ‘shopify-api-node’;

const shopifyCon = new Shopify({
shopName: ‘demo-shopname’,
accessToken: ‘ACCESSTOKEN’,
apiVersion: ‘2023-04’
});

const createFulfillment = async (orderId, fulfillmentData) => {
try {
const fulfillment = await shopifyCon.fulfillment.create(orderId, fulfillmentData);
console.log(‘Fulfillment created:’, fulfillment);
} catch (error) {
console.error(‘Error creating fulfillment:’, error);
}
};

// Usage example:
const orderId = ‘123456789’; // Replace with your order ID
const fulfillmentData = {
tracking_number: ‘1234567890’, // Replace with the tracking number
tracking_urls: [‘https://example.com/tracking’], // Replace with the tracking URL(s)
line_items: [
{
id: ‘987654321’, // Replace with the line item ID
quantity: 1 // Replace with the quantity to fulfill
}
]
};

createFulfillment(orderId, fulfillmentData);

I am getting this error

Error creating fulfillment: HTTPError: Response code 400 (Bad Request)

code: ‘ERR_NON_2XX_3XX_RESPONSE’,
timings: {
start: 1685883653312,
socket: 1685883653314,
lookup: 1685883653369,
connect: 1685883653449,
secureConnect: 1685883653527,
upload: 1685883653529,
response: 1685883654072,
end: 1685883654075,
error: undefined,
abort: undefined,
phases: {
wait: 2,
dns: 55,
tcp: 80,
tls: 78,
request: 2,
firstByte: 543,
download: 3,
total: 763
}
}
}

I can fetch the order details using this code :

const shopOrder = await shopifyCon.order.get(orderId);

But fulfilment creation is giving me an error. Please guide.

Hi There,

That is a 3rd party package not written by Shopify itself, so you may have a hard time getting any real help with that. Your best bet is to contact the developer directly.

Sorry can’t be of more help to you.

Cheers,

Gary

Hello Irfanrasool,

We had the same issue and was solved migration to the new fulfillment service createV2.

Here there is the documentation: https://shopify.dev/docs/api/admin-rest/2023-04/resources/fulfillment#post-fulfillments to the params of the request.

Best !

Hey Robles,

I’m using the following params for createV2, but still getting either bad request or 404 responses:

{
line_items_by_fulfillment_order: [
{
fulfillment_order_id: order.id,
},
],
}

also tried:

{
fulfillment: {
line_items_by_fulfillment_order: [
{
fulfillment_order_id: order.id,
},
],
},
}

Would you be able to let me know how your params are structured (without sensitive data of course)?

Hey there,

You are passing the wrong Id for fulfillment_order_id. It should not be the
order.id it should be the fulfillment_order.id

Cheers

1 Like

Thanks! As soon as I pasted the code, I realised what I was doing wrong! Thanks heaps!

I can explain what might have happened in a simpler way.

Sometimes, when you change a store URL and set up a redirect to the new address, there can be a technical glitch. This glitch can cause you dont fetch products from store.

It sounds like you encountered this error. But you were able to fix it by removing the redirect and setting the default URL as the primary one.