skip to Main Content

I’m trying to update an order in Shopify as fulfilled.

I’m using Javascript code.

I tried using both the order and the filfillment IDs.

Each order has multiple line items but I want to update the entire order. And the API documentation says if you update the fulfillment ID and not specify line items it will fulfill the entire order.

This is the code I’m using.

It runs and doesn’t return an error, but the order isn’t fulfilled.

(Oh, I added the output because the tools I am using requires it, but I really don’t need it)

Help….

    const fulfillmentOrderId = 'f_ID';
const newStatus = 'FULFILLED'; // or 'partial'

const updateFulfillmentStatus = async () => {
  const response = await fetch(
    `https://******.myshopify.com/admin/api/2024-01/fulfillment_orders/${fulfillmentOrderId}.json`,
    {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
        'X-Shopify-Access-Token': 's****_******'
      },
      body: JSON.stringify({
        "fulfillment_order": {
          "location_id": "123456789",
          "id": fulfillmentOrderId,
          "status": newStatus
        }
      })
    }
  );

  const data = await response.json();
  console.log(data); // Handle the response as per your requirements
};

updateFulfillmentStatus();


output=updateFulfillmentStatus()

2

Answers


  1. Chosen as BEST ANSWER

    Here's the code I'm using. It works in theory, only I keep getting a response of OrderID not found

    // Replace YOUR_SHOPIFY_STORE, ACCESS_TOKEN, ORDER_ID, and LOCATION_ID with your actual values
    const shopifyStore = '******';
    const accessToken = 's****_********';
    const orderId = '123456789'; // Replace with the order ID
    const locationId = '123456789'; // Replace with the actual location ID
    
    // Endpoint 
    const endpoint = `https://${shopifyStore}.myshopify.com/admin/api/2024-01/orders/${orderId}/fulfillments.json`;
    
    // Replace with the necessary data for fulfillment
    const fulfillmentData = {
      fulfillment: {
        // Add fulfillment details here
        location_id: locationId,
        // other fulfillment details...
      }
    };
    
    // Make the API request
    fetch(endpoint, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-Shopify-Access-Token': accessToken,
      },
    body: JSON.stringify(fulfillmentData),
    })
      .then(response => {
        console.log('Order ID:', orderId); // Log the order ID
        console.log('Endpoint:', endpoint); // Log the endpoint
    
        console.log('Response Status:', response.status);
        console.log('Response Headers:', response.headers);
    
        if (response.status === 404) {
          console.error('Order not found. Check the order ID.');
          return Promise.reject(new Error('Order not found.'));
        }
    
        // Check if the response status is okay before attempting to parse JSON
        if (response.ok) {
          return response.json();
        } else {
          throw new Error(`HTTP error! Status: ${response.status}`);
        }
      })
      .then(data => {
        console.log('Fulfillment created:', data);
        // Call the Zapier callback with the result
        callback(null, data);
      })
      .catch(error => {
        console.error('Error creating fulfillment:', error);
        // Call the Zapier callback with the error
        callback(error);
      });
    

  2. There is no such thing as fulfillment order updates like that. If you want to make a fulfillment, use the mutation fulfillmentCreateV2 where you provide the fulfillment order ID and anything else of any interest. Not sure where you got your ideas from here, but there is nothing matching in the docs far as I can tell. I have fulfilled a few million orders using fulfillmentCreateV2, so I can attest to the fact that it is simple and just works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search