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?
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.