Skip to main content

Hi,

 

Zapier allows Create and Search actions. But what about Do type actions? I have an API method that will be used at the end of a Zap (so does not need to pass anything to another action step).My API currently either returns an empty OK (200) or a BadRequest (400) with the error as a string.

I currently get this:

“Invalid API Response: - Got a non-object result, expected an object from create”

How do I go about creating the action in the Zapier developer console re: dealing with the return result? I guess I have to switch to code mode but what would my code look like to deal with errors and OKs?

My code currently looks like this:

...

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;

    // You can do any parsing you need for results here before returning them

    return results;
  });

 

Thank you,

Steve

Paging @ikbelkirasan for this.


Hi @borgs_uk - How about this, does it solve the problem?

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
if (!results) {
return {
response: "OK",
};
}
return results;
});

 


Hi @borgs_uk - How about this, does it solve the problem?

return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
if (!results) {
return {
response: "OK",
};
}
return results;
});

 

Many thanks to you both. That is doing the trick nicely. And, if a 400 error is returned by my API then the throwForStatus is being triggered and leading to me to getting a Zapier alert for the failed Zap - which is good.

Thank you.