How to Handle JSON Responses from a Fetch Request in Zapier?

I’m experiencing difficulties with Zapier while trying to retrieve some information. My goal is to perform a GET request, obtain a JSON response, and pass it on for further processing in the next step. However, it appears that Zapier is overlooking the callback I implemented and is forwarding a non-JSON ‘zapier formatted’ response instead. Below is the example code I am using to make the request:

var headers = {
    'Authorization': 'Bearer xxxx',
    'Content-Type': 'application/json'
};
var fetchOptions = {
  method: 'GET',
  headers: headers
};

fetch('www.url.com', fetchOptions)
  .then(function(response) {
    return response.json();
  })
  .then(function (data) {
    callback(null, data);
  })
  .catch(callback);

For the next step in Zapier, I need the actual client response, not the modified one, to allow for typical JSON parsing and looping. I want to filter for all cats that are green:

cats.filter(function(cat){
  return cat.color === 'green';
});

How can I achieve this when the attributes of the cats are separated into different Zapier fields? I also attempted to restructure the response after my GET request, but Zapier seems to ignore my directions. For reference, here’s what I tried:

fetch('www.url.com', fetchOptions)
  .then(function(response) {
    callback(null, {pet: 'yorkie'});
  })
  .catch(callback);

This code should return the specified object, but instead, I continue to receive the same formatted response from Zapier. When I skipped the callback and directly made the fetch call, it still produced the same ‘zapier formatted’ response:

fetch('www.url.com', fetchOptions);

I’ve had similar issues with Zapier processing JSON responses, and after much trial and error, it turned out that relying too heavily on callbacks can sometimes be misleading since Zapier might handle it differently than a traditional environment. What worked for me was using Zapier’s built-in code steps to restructure the response before passing it to the next steps. Ensure you’re using Zapier’s Code by Zapier app to write a custom JavaScript function that parses JSON and makes use of output objects. By doing this, you can have more control over how data moves between steps. Lastly, make sure you’re mapping the fields correctly while setting up subsequent actions; you may need to use Zapier’s inbuilt tools for organizing fields or performing lookups. Double-check if the data is in line with what Zapier expects, which might help prevent automatic re-formatting.

I’ve faced similar stuff too! Zapier is kinda picky with JSON things. Try using the “Code by Zapier” action to handle the response data in a more flexible way. You might need to tweak the output object to fit what Zapier wants. Also, re-check your headers—sometimes small errors can mess everything up!

I’ve run into this issue as well when working with JSON in Zapier projects. One approach that helped me was using a separate function to properly transform the JSON response prior to utilizing it in Zapier. You need to ensure that when using the ‘Code by Zapier’, the function properly unpacks and repackages the data in a way that aligns with how Zapier integrates field sets. Try deferring the response handling to a script within Zapier itself, which may give additional flexibility for handling arrays and objects, especially for nested JSON structures. This can often prevent unwanted restructuring by Zapier.

It’s essential to grasp how Zapier interprets external JSON responses. One method you could explore involves checking if the JSON response structure aligns with how Zapier splits data into individual fields. Since fields in Zapier correspond to keys in the JSON object, restructuring your response by wrapping them in a single top-level object might help. Additionally, consider using “Code by Zapier” to loop over the JSON response manually. This approach fixes the field separation issue and lets you apply filters like selecting green cats directly. Although it might require testing adjustments, it grants more precise data handling at each step.