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

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

irfanrasool
Visitor
1 0 0

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.
Replies 6 (6)

garyrgilbert
Shopify Partner
430 41 181

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

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution

Robles
Tourist
4 0 3

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 !

Prav
Shopify Partner
6 0 1

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)?
If you find the answer helpful give it a Like and ✓ Mark it as an Accepted Solution.
garyrgilbert
Shopify Partner
430 41 181
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
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Prav
Shopify Partner
6 0 1

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

If you find the answer helpful give it a Like and ✓ Mark it as an Accepted Solution.

anisulislam
Visitor
1 0 0
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.