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

Creating a new test run from Javascript AJAX


This is my first time using the TestRail API. I running a javascript file with Node and Jquery, and am trying to create a new test run from the script. Here is what I have so far

var newRunData = {
    "suite_id": "S9273",
    "name": "[TEST] Automation - v1.6 Build #248 - 2017-08-14 15:38"
    type: "POST",
    url: "index.php?/api/v2/add_run/:P16",
    dataType: 'json',
    data: newRunData,
    beforeSend: function(xhr)
        xhr.setRequestHeader("Content-Type", "application/json");
        xhr.setRequestHeader("X-Requested-With", "API Client");
    error: function(error)

But aren’t I missing something important? Where/how do I actually log in to the account with the API key? Where do I specify the url to our TestRail? Am I supposed to have a local index.php?

Can someone give me a complete example of using the API with Ajax?


You need to use basic authentication in the call (i.e. pass the credentials in the header). This page ( has some examples for general REST API calls with jQuery/ajax.