Skip to main content
Best answer

Calling an API method that returns an empty OK (200) or Bad Request (400)

  • November 4, 2020
  • 3 replies
  • 968 views

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

Best answer by ikbelkirasanBest answer by ikbelkirasan

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;
});

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

AndrewJDavison_Luhhu
Forum|alt.badge.img+10

Paging @ikbelkirasan for this.


ikbelkirasan
Forum|alt.badge.img+12
  • Zapier Expert
  • 555 replies
  • Answer
  • November 4, 2020

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;
});

 


  • Author
  • Beginner
  • 4 replies
  • November 5, 2020
ikbelkirasan wrote:

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.