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

Examples: accessing the API via UI Scripts with session authentication


Hi guys - on the Admin page for the API integration there is the following information:

Just wondering if you have any examples for accessing the API methods via UI scripts?



Hello Glenn,

Thanks for your posting. We don’t currently have a full example on but you can use the following example:

[code]name: Example request for the API
description: Shows how to use TestRail’s API via JavaScript
author: Gurock Software
version: 1.0
includes: ^cases/view

(document).ready( function() { .ajax(
url: ‘index.php?api/v2/get_case/’ +,
dataType: ‘json’,
beforeSend: function(xhr, settings)
xhr.setRequestHeader(“Content-Type”, “application/json”);
success: function(data, status, xhr)
error: function(xhr, status, error)

This adds a new UI script to the test case view page that reads the current test case via the API. It uses the UI script context for the current test case ID and then issues a get_case API request to read the case from the API:

I hope this helps!


[UI Script] Make Estimate field required

Thanks Tobias! That’s perfect as a starting point :slight_smile:


Definitely a +1!



Do you have an example of how to access the API with a POST command such as add_case or update_case?