Automatically update Shopify order to Prepared when a new order is recorded in Google Sheets via Zapier

Using Zapier, change Shopify order status to ‘prepared’ when a new order enters Google Sheets. Below is revised sample code ensuring API compatibility:

async function changeStatus(orderNum) {
  const shopURL = 'https://mynewshop.myshopify.com';
  const authToken = 'new-token';
  const statusUpdate = 'prepared';
  const result = await fetch(`${shopURL}/admin/api/2024-04/orders/${orderNum}/status.json`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Basic ${authToken}`
    },
    body: JSON.stringify({ status: statusUpdate })
  });
  return result.json();
}

hey, this code worked fine for me. mayb add error checking to avoid silent fails when api version shifts. cheers!

Based on my own experience working on a similar integration, I found that creating more detailed logs even before running the API call helped identify issues early on. I encountered situations where the API call seemed to execute correctly but the order status was not updated because of hidden errors in the response. In such cases, extending the code with additional try-catch blocks and verbose logging made diagnosing the problem easier. I also made sure to monitor API version changes regularly, as that ensured compatibility with Shopify’s updates.