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

Users API?


#1

Hi,
We have a post processing code that we execute after out automation tests in Jenkins/Bamboo/etc. The code parses the various results xml files and puts the results into testrails. Because different people own these reports, we like to assign the results to the appropriate people.

Currently, this java post processing command works like this

java -jar testrail_post_process.jar …

At the moment I can use manually hard code each user’s id in Jenkins because I am the administrator. However, it would be nice to have a user API which can return a userid given a user’s email address. This way the design would be a lot cleaner

java -jar testrail_post_process.jar …

Thanks

Ali


#2

Hello Ali,

Thanks for your posting. There’s currently no API for getting a list of users unfortunately. I’ve added this as a feature request. You could extend the mini API (or better, add your own API) if you prefer this until this is available. Just let me know in case you need help with this (the mini API comes with source code, so it’s quite simple to add new API methods/your own custom API).

Regards,
Tobias


#3

Hi Tobias,
Can you direct me to how to write my own API or extend the current one?

Thanks

Ali


#4

Hello Ali,

We don’t currently have documentation on how to customize the API unfortunately, but you would basically create your own API files and add your own API methods with the same calling conventions as the official API (using the existing miniapi.php files as a reference). Please note that this is only supported for read-only methods (as in your case). I will prepare a small example for your use case (this may take a day if that’s okay).

Regards,
Tobias


#5

Hello Ali,

Please see below for the relevant code snippets:

arguments/miniapi.php: $arguments['get_user_by_email'] = array( 'methods' => 'get', 'rules' => array( 'get:email' => array( 'type' => 'email', 'label' => 'Email', 'required' => true ) ) );

[code]controllers/miniapi.php:
private function _get_user_by_email($email)
{
$this->db->select(‘id’);
$this->db->select(‘name’);
$this->db->select(‘email’);
$this->db->select(‘is_active’);
$this->db->select(‘is_admin’);
$this->db->from(‘users’);
$this->db->where(‘email’, $email);
return $this->db->get_row();
}

public function get_user_by_email($email)
{
$user = $this->_get_user_by_email($email);
ajax::return_success(array(‘user’ => $user));
}[/code]

This adds a new get_user_by_email to the API. You can alternatively put this method into its own API files (so that new API versions don’t override your changes). You would just need to copy the argument/controller files of the mini API and create a new pair of files (e.g. under the custom directories, i.e. arguments/custom/miniapi.php and controllers/custom/miniapi.php) and remove the existing API methods (and add your own methods). Please let me know in case you have any questions.

Regards,
Tobias


#6

Thanks Tobais. Works great now.


#7

That’s great, thanks for the update.

Regards,
Tobias


#8

Tobias,

I see in your online reference for the API V2 that there is a method called ‘get_users’. It returns a list of users. I downloaded the TestRail API and tried it but it looks like that method was never implemented. Is there an updated API V2?


#9

Never mind. I got it to work.


#10

Hi John,

Thanks for your posting. The v2 API is built into TestRail and only the previous mini API required a separate download but good to hear that you got it working already!

Cheers,
Tobias


#11

So now I’m a little confused. On your website under the API binding you instantiate a new api client with this line.

$client = new TestRailAPIClient(‘http://’);

This only works when I have the testrail.php that I downloaded in the ‘require’

If I don’t have that file how do I instantiate a new api client?


#12

Hi John,

I was referring to the server part which is now included directly with TestRail. I thought you were talking about the previous mini API which was a separate download. The binding needs to be downloaded separately and you can then include/require the testrail.php file to make API calls from your code.

Cheers,
Tobias