Server environment causing 400 bad request error on api call?


Moving the site from staging server to production server has resulted in the 400 bad request error. It is exactly the same code that works fine on the staging server. The get_headers request returns the following:

Array ( [0] => HTTP/1.0 404 Not Found [1] => X-RateLimit-Limit: 150 [2] => X-RateLimit-Remaining: 132 [3] => X-RateLimit-Reset: 1338576073 [4] => X-RateLimit-Class: api [5] => Last-Modified: Fri, 01 Jun 2012 17:41:32 GMT [6] => Expires: Tue, 31 Mar 1981 05:00:00 GMT [7] => Pragma: no-cache [8] => Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0 [9] => Set-Cookie: guest_id=“v1:133857249231372253”;Expires=Sun, 1-Jun-14 17:41:32 GMT;Path=/; [10] => Status: 404 Not Found [11] => X-Transaction: b49bb5d201269094 [12] => X-Frame-Options: SAMEORIGIN [13] => Date: Fri, 01 Jun 2012 17:41:32 GMT [14] => Content-Type: application/xml; charset=utf-8 [15] => Content-Length: 116 [16] => Server: tfe [17] => Connection: Keep-Alive )

Clearly the rate limit is not being reached, plus it shows that it is a 404 error. But when I run the script I get this:

Warning: simplexml_load_file( [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

showing a 400 error.

Works on staging server but not live site so it must be hosting environment, but what to look for? Curl is enabled, simpleXML is installed.

Any ideas?


We really recommend using a more robust instrument than simplexml_load_file. You will likely also want to leverage OAuth.

There are bodies to the errors we send. The body will contain more information as to why you’ve gotten the error you got. I’m not sure if simplexml_load_file is capable of telling you what those errors are. You’ll need to investigate.

The URL pattern you’re trying to use is also outdated. Consider using and so on instead. 400 errors are a normal part of operations. Understand their meaning and handle them with exception handling.


Thanks Taylor,
that was the full error I posted except for the file reference, which has sensitive server info I wouldn’t make public.

I am using exception handling, but it doesn’t solve the problem. I used the dev api console to try a few different calls. In the end the only one that worked is this:

It’s probably deprecated but it works. Maybe the server people can shed some light.