Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

GET API Error - Response for preflight has invalid HTTP status code 400



I am trying to make AJAX call to Test Rail GET APIs and all of them are returning me HTTP 400 error. In my browser console I see following 2 errors.

  1. Failed to load resource: the server responded with a status of 400 (Bad Request)
  2. XMLHttpRequest cannot load https://<my_testrail_server>/index.php?/api/v2/get_project/<my_project_id>. Response for preflight has invalid HTTP status code 400.

Here is my code:

(document).ready(function() { .ajax({
crossDomain: true,

            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'Basic ' + btoa('username:password'));
                xhr.setRequestHeader('Content-Type', 'application/json');
    url: "https://<my_testrail_server>/index.php?/api/v2/get_project/<my_project_id>",
    type : "GET",
    dataType : "json"

}).then(function(data, status, jqxhr) {


Please let me know what I am missing. Any help is much appreciated.


Hi Piyush!

You can find a fully working example here:

TestRail’s returns 400 responses in case of invalid requests which can be anything from invalid JSON you submit or invalid arguments such as an unknown project. TestRail would return additional details in the request response (i.e. an explanation why you see a 400).

I hope this helps!