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

Generated API keys don't allow to use the testrail API


I’m trying to use an API Key instead of my TestRail UI password, but for some reason it doesn’t work, I can’t log in into the API using any generated api key "TestRail API returned HTTP 401(“Authentication failed: invalid or missing user/password or session cookie.”)"

can you please help me?


Difficulty to access TestRail via its API (error 401)

Hi Diego,

Thanks for your posting. Please make sure to also specify the email address as part of the API call and the API keys are a drop in replacement for the user password. It’s also important to save the My Settings page first before you can use the API keys.

I hope this helps!



So I need to provide value for the user variable and then use the API key to make the call? I tried that but I still get a HTTP 401 error


Hello Shiva,

Thanks for your posting! The API keys are a drop-in replacement for user passwords and you can authenticate API requests using the user email address and an API key. If you are using one of the API bindings, you can specify the API key via the password field/function:

I hope this helps!




I am facing similar issue. I am trying to use test rail api with api key and I am getting 401. I am using it with python. Here is the code I am trying(downloaded from and just changed user and password part):

class APIClient:
    def __init__(self, base_url):
        self.user = 'MY_EMAIL'
        self.password = 'MY_API_KEY'  # api key

        if not base_url.endswith('/'):
            base_url += '/'
        self.__url = base_url + 'index.php?/api/v2/'


Hi Rujoota,

Thanks for your posting! Sure, happy to help. The API keys are a drop-in replacement for the user password. Did you save the My Settings after adding the API key? Is there a reason why you modified the APIClient class instead of setting the username and password as shown in our example?



Hi ,

Even i am getting the 401 error . But i am not using the KEY . I am using the email id and the password that i use to login to the test rail local instance via browser . Am i missing something here .


Hi @saradha,

Do you use one of our official API bindings? Please double-check that the username and password are correct and you can also try using an API key to see if this makes a difference.



Hi Tobias,

Yeah i downloaded the bindings from the site only . I am using the same password and id that i used to login to the testrail instance via browser. Also i am not able to use the key as i dont see that option in my settings page .


Hi Saradha,

You can add API keys on your My Settings page on the API Keys tab:

Can you also try this please?



Hi Tobias,

I am not seeing this tab itself. Only the users and settings tab are visible in the My settings page.

Kindly help please



Hi Saradha,

Which TR version do you use? The API keys were added with TR 4.2 and you can see the API Keys tab in the screenshot above (on the My Settings page).



Hi @tgurock

Am trying to access TestRail API using JavaScript. but i didn’t see any JavaScript binding mentioned in TestRail official bindings…! Can we access using JavaScript(nodeJS) ? I have tried placing API , usename to access TestRail API using plain nodejs get, post methods and also using frisby, but am still having the following error
"{ error: ‘Authentication failed: invalid or missing user/password or session cookie.’ }", with 401 Http response.



Hi Harsha,

Thanks for your posting. Yes, you can also use TestRail from JavaScript/nodejs and there are already a few (customer-provided) example modules you can look into:

When adding API keys, it’s important to save the My Settings form and only this would permanently store the API key in TestRail.

I hope this helps!



It just does not work
It works with password but not apikey name

yes, api key should be an actual character sequence, not the name of the api.

curl -v -I -H “Content-Type: application/json” -u "" "“



When attempting this you are making sure that you are in fact saving the API key in the UI? if this is not saved, then this function will not work.


It took me a few minutes and adding logging to to understand tgurock’s answers but if anyone else is having trouble with using API keys in python, the simple/plain answer is thus:

import testrail
project_id = 123
client = testrail.APIClient(your_testrail_url)
client.user = ''   # not just username
client.password = 'xxx'  # the API key from testrail ---> My Settings ---> API Keys

response = client.send_get(f'get_cases/{project_id}')
print(f'Response: {response}')


Thank you retsigam for the added clarification.