Attempting to Replicate GraphQL Query in Shopify Flow is Failing

Attempting to Replicate GraphQL Query in Shopify Flow is Failing

holo_haven
Shopify Partner
1 0 0

Hey guys!

 

I'm trying to use Shopify Flow to automatically update the variant cost and a few other variant level fields when triggered in Flow. I've developed the query I want, and have it running properly in a Google Script (Javascript with a Google wrapper), but when I attempt to move it over to Flow it breaks down. Here's what I have - 

 

function pushToShopify() {
  var headers = {
    'X-Shopify-Access-Token': password,
  }
  let query = JSON.stringify({
    query: 'mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) { inventoryItemUpdate(id: $id, input: $input) { inventoryItem { id unitCost { amount } } userErrors { message } } }',
    "variables": {
      "id": "gid://shopify/InventoryItem/49216882835776",
      "input": {
        "cost": 0.1,
        "tracked": false,
        "countryCodeOfOrigin": "US",
      }
    }
  });

  var options = {
    method: 'POST',
    headers: headers,
    contentType: "application/json",
    payload: query,
    muteHttpExceptions: true
  }
  var url = "https://[my-store].myshopify.com/admin/api/2025-01/graphql.json";
  Logger.log(url);
  Logger.log(options);
  var resp = UrlFetchApp.fetch(url, options);

  Logger.log(resp)

  let object = JSON.parse(resp.getContentText())
  Logger.log(object)
  return [JSON.parse(resp.getContentText()), resp.getHeaders()]

}

 

Here's the response I get in Google Script - 

{"data":{"inventoryItemUpdate":{"inventoryItem":{"id":"gid://shopify/InventoryItem/49216882835776","unitCost":{"amount":"0.1"},"tracked":false,"countryCodeOfOrigin":"US"},"userErrors":[]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1990,"restoreRate":100.0}}}}

 

So I attempted to migrate this to Shopify Flow, using the Send HTTP request Action with the following details - 

holo_haven_0-1736469881255.png

 

And this is the exception I receive - 

{"status":400,"response_body":"Bad Request","verb":"POST","url":"https://core.sfe.shopifyinternal.com/admin/api/2025-01/graphql.json","request_body":"\"query\":\"mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) { inventoryItemUpdate(id: $id, input: $input) { inventoryItem { id unitCost { amount } tracked countryCodeOfOrigin} userErrors { message } } }\",\"variables\":{\"id\":\"gid://shopify/InventoryItem/49216882835776\",\"input\":{\"cost\":0.1,\"tracked\":false,\"countryCodeOfOrigin\":\"US\"}}"}

 

I cannot figure out what's going on. This works flawless in Google Script, but I always get a Bad Request exception whenever I attempt to run this in Flow. To note, I regularly run other HTTP requests in Flow such as the one in the screenshot below and so I have had some success with this before, but not sure what I'm doing wrong. Any ideas?

holo_haven_1-1736470104718.png

 

 

 

Replies 2 (2)

RPiii
Shopify Staff
109 18 36

Is there a reason you're using Send HTTP request instead of Send Admin API request? The latter is more secure and less expensive. For reference, Flow currently uses Admin API version 2024-04.

paul_n
Shopify Staff
1482 160 346

Also:

  • Way easier to use
  • Returns data if needed
Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.