2

Working on creating a custom zapier integration using zapier CLI. My API endpoint is not technically a create, but it uses the POST method so I made it under the create definition in zapier. I set my output fields to empty, but it breaks on my empty response object.

outputFields: []

The error message:

We had trouble sending your test through.
Unexpected end of JSON input
Hide details
Troubleshooting Errors | Contact Support
What happened (You are seeing this because you are an admin):
  Starting POST request to https://api.fake.com/v2/demo-finance/live/csh-search
  Received 202 code from https://api.fake.com/v2/demo-finance/live/csh-search after 596ms
  Received content ""
  Unexpected end of JSON input

Everything is working as expected the request went through it is just not happy with the empty string response not being valid JSON. Is there some way to tell zapier this is an acceptable response object?

Nick Ellis
  • 1,048
  • 11
  • 24

1 Answers1

1

David here, from the Zapier Platform team.

It's fine if your API works that way, but you still need to return something json serializable from your function. Try something like this:

const performCreate = async (z, bundle) => {
  const response = await z.request('https://api.fake.com/v2/demo-finance/live/csh-search')
  if (response.statusCode === 202) {
    return {}
  }
  // handle errors, other cases, whatever
  // just make sure to return an object
}

As a side note, just because the request uses a POST request doesn't mean it needs to be a Create; it should be whatever type makes the most sense for the operation. If it's a search (like the fake url suggests) a search is probably the way to go.

xavdid
  • 5,092
  • 3
  • 20
  • 32
  • The path is misleading it is not a search function. It is something that I want to behave as an action. So something triggers and then this action is performed, that's why I made it a create. If I can have it be an action but define it under a different type in zapier it's all the same to me. – Nick Ellis Apr 02 '19 at 13:39
  • Cool, no problem. Did the rest of the answer solve your problem? – xavdid Apr 02 '19 at 14:53
  • It absolutely did. I simply forgot to mark it as correct. Thanks a lot! – Nick Ellis Apr 02 '19 at 17:05