Modify fulfillment status and Adding Tracking information

Solved

Modify fulfillment status and Adding Tracking information

raulvaquerizo
Shopify Partner
13 3 5

Hello,

 

I am attempting to update the fulfillment status to 'fulfilled' and include additional information such as the tracking number using the Shopify API.

Currently, I can modify other fields, such as note_attributes, but I'm encountering difficulties updating the fulfillment status. I'm unsure if I should be updating the order from the following URL: https://${store}.myshopify.com/admin/api/2024-01/orders/${orderId}.json or if there's another endpoint for fulfillment updates.

 

const updateData = {
  order: {
    id: orderId,
    fulfillment_status: 'fulfilled',
  },
  fulfillments: [
    {
      location_id: locationId,
      tracking_company: 'GLS',
      tracking_number: trackingNumber,
      tracking_numbers: [trackingNumber],
      tracking_url: `https://gls-group.eu/EU/en/parcel-tracking?match=${trackingNumber}`,
      tracking_urls: [`https://gls-group.eu/EU/en/parcel-tracking?match=${trackingNumber}`],
      status: 'success',
      service: 'manual',
    },
  ],
  note_attributes: [
    {
      name: 'Order status:',
      value: trackingNumber,
    },
  ],
};

const updateUrl = `https://${store}.myshopify.com/admin/api/2024-01/orders/${orderId}.json`;
console.log('Update URL:', updateUrl);

const updateResponse = await axios.put(updateUrl, updateData, {
  headers: {
    'X-Shopify-Access-Token': adminApiAccessToken,
    'Content-Type': 'application/json',
  },
});

Could you please guide me on the correct approach or provide any insights into what might be causing the issue?

 

Thank you for your assistance.

Best regards

 

Accepted Solution (1)

raulvaquerizo
Shopify Partner
13 3 5

This is an accepted solution.

Solution:

The solution that finally worked for me was using the shopify-api-node library. Here is the code that resolved my issue:

const fulfillmentDetails = await shopify.order.fulfillmentOrders(orderId);
const fulfillmentOrderId = fulfillmentDetails[0].id;
const fulfillmentLineitemIds = fulfillmentDetails[0].line_items.map(item => ({
    id: item.id,
    quantity: item.quantity
}));

const updateParams = {
    line_items_by_fulfillment_order: [
        {
            fulfillment_order_id: fulfillmentOrderId,
            fulfillment_order_line_items: fulfillmentLineitemIds
        }
    ],
    tracking_info: {
        number: trackingNumber,
        url: `https://company.eu/EU/en/parcel-tracking?match=${trackingNumber}`,
        company: 'company'
    },
    notify_customer: true,
    origin_address: null,
    message: 'Delivery status: ' + trackingNumber
};

const updateFulfillment = await shopify.fulfillment.createV2(updateParams);

I hope this proves helpful for those who may encounter a similar issue. Thanks to the community for the support!

Best regards!

View solution in original post

Replies 2 (2)

raulvaquerizo
Shopify Partner
13 3 5

This is an accepted solution.

Solution:

The solution that finally worked for me was using the shopify-api-node library. Here is the code that resolved my issue:

const fulfillmentDetails = await shopify.order.fulfillmentOrders(orderId);
const fulfillmentOrderId = fulfillmentDetails[0].id;
const fulfillmentLineitemIds = fulfillmentDetails[0].line_items.map(item => ({
    id: item.id,
    quantity: item.quantity
}));

const updateParams = {
    line_items_by_fulfillment_order: [
        {
            fulfillment_order_id: fulfillmentOrderId,
            fulfillment_order_line_items: fulfillmentLineitemIds
        }
    ],
    tracking_info: {
        number: trackingNumber,
        url: `https://company.eu/EU/en/parcel-tracking?match=${trackingNumber}`,
        company: 'company'
    },
    notify_customer: true,
    origin_address: null,
    message: 'Delivery status: ' + trackingNumber
};

const updateFulfillment = await shopify.fulfillment.createV2(updateParams);

I hope this proves helpful for those who may encounter a similar issue. Thanks to the community for the support!

Best regards!

ideaadeaa
Tourist
6 0 0

Hello Raulvaquerizo,

 

I'm currently struggling to change the link of "fulfillment.tracking_urls" . Now it's redirecting the customers to UPS while I want them to go track on my own website page. I barely have any coding knowledge, only know bare minimum. Found this Q-A of yours that tend to be similar(?) hahah. Is it the same problem you were trying to solve? Is there any chance that you would know how to customize the tracking url in the customers emails? Thank you in advance.

 

Best Regards,

Irin