1

I am building an integration with Zapier (https://zapier.com/platform) and I want to throw an error but it seems like it's not working properly.

My authentication code (dumbed down for the purpose of this post):

if($_POST['api_key'] === $row['api_key']) {
    $array = ['success' => 'yes'];
    echo json_encode($array);
} else {
    echo "Sorry but that is the invalid API token. Please try something else";
}

When I try to test that in the Zapier developer platform, I get this message from them:

Error parsing response. We got: "Sorry but that is the invalid API token. Please try something else". This is likely a problem with the app. Please contact support at contact@zapier.com

But Zapier wants me to throw an error that does not have the "Error parsing response" and "This is likely a problem with the app..." parts....

How can I fix this?

pixie123
  • 929
  • 3
  • 14
  • 27
  • 1
    It's likely expecting a specific JSON-formatted response which you are not providing. – Alex Howansky Jun 25 '19 at 16:51
  • @AlexHowansky Yes I know that but if I provide JSON response, it shows "success". Not sure if that's what it is supposed to actually show... – pixie123 Jun 25 '19 at 16:59

1 Answers1

1

Simply sending a message that the auth was unsuccessful isn't enough - you need to also send the appropriate HTTP response code. In this case, you probably want 403 or 401. I'm not sure how to do that, but there plenty of questions that'll point you in the right direction.

Additionally, you probably want to send back JSON rather than plain text. This could be as simple as: {"message": "invalid token"}. This'll help the client better surface that info to the user.

xavdid
  • 5,092
  • 3
  • 20
  • 32
  • 1
    Hey @xavdid - I tried sending this JSON response but Zapier still doesn't pick the value under "message" key to show the same to the user. Is there anything I am missing. Just to let you know I was also sending the proper HTTP response code as well. – prateek31 Dec 19 '19 at 11:41
  • Zapier won't automatically pick up the `message` key unless you are specifically looking for it. I just used that as a simple example. You'll need to handle that error manually – xavdid Dec 21 '19 at 07:46