I'm successfully adding contacts, but I'm having trouble returning a response that is useful to me. I need a plain "true" or "false" response, but instead I get either
"Error 409: Email address email@example.com is already a contact"
or I get a whole string for the successful add.
How can I get a simple "true" or false" returned?
The API returns varied responses to facilitate troubleshooting of requests in the event of errors. If you want simpler success/fail results, you'll need to read the response into a string, check for the error codes that indicate successes (200, 201, 204, depending on request type). If you find them, you can record/report a success, if not, you can record/report a failure. Of course, that won't help much in determining why your request wasn't successful. A 409, for example, means the contact was already in your account, but not necessarily that it is already on the list to which you tried to add it in your request (see here).
I hope this helps.
I was afraid of that.
So, I took the next step of adding $httpcode = curl_setopt($ch, CURLINFO_HTTP_CODE); and trying to return that, then based on the code returned, return a success or failure. But it's returning nothing. Any reason you can think it would do that?
I just noticed that my success message does not contain any codes at all. Here's a sample that I'm getting back:
Contactmarcusbrody1@gmail.com Jeremiah Lewis 90034 ACTION_BY_CUSTOMER Active HTML Jeremiah Lewis true 2012-06-26T23:06:58.949Z 2012-06-26T23:06:58.000Z
Now I'm really confused, since documentation seems to indicate I should be getting back either 200 or 201 or 204 if the request is successful.
What you've posted is the body of the server response, which is returned as xml that includes information about the contact resources created in this case. To get the response code, you could use the curl_getinfo() function, which returns the status of the last curl request. It can be implemented something like this:
$http_status = curl_getinfo($http, CURLINFO_HTTP_CODE); echo $http_status;
I hope that helps get you on track.