With this article, you will find an example of all the steps that should be made when you want to use REST API for Xray Cloud. Please note: 

  • This is an example. You have several reports formats you can use and several endpoints for different actions. 
  • This article should be used to understand all the steps that have to be made when we want to use the REST API by using the Command-line interface.

Step-by-step guide

Note: This is an example

1 – Run your tests by using the TestNG framework, and get the TestNG XML report.

2 – Then, you can import your Execution results by using the REST API.

3 – First, you need to authenticate. Requests made to Xray's REST API must be authenticated based on an API Key.

3.1 - Define your API KEY

Go to Jira settings > Apps > Xray > API Keys

3.2 - Then Create API Key > Search for your user

3.3 - Click Generate

3.4 - Now you have two informations: Client ID and Client Secret

3.5 - Obtain a token

You can use the command prompt and use this example requests to get the token id (command line):

curl -H "Content-Type: application/json" -X POST --data "{ ""client_id"": ""D7E89339C2534491A017BB25BBDFBC8B"",""client_secret"": ""30dc3492cfc463cf24b098a7f40e521229b3d629832644df0198b8bf3801be51"" }" https://xray.cloud.getxray.app/api/v1/authenticate

The output will be a string like this one:

This token will have a duration of 24hours. 

4 – Import results

4.1 - Go to your command line.

4.2 – Change your directory to the folder where you have your report:

4.3 – Use one of the following scripts to import execution results:

More details here

Note: If you want to have control over the fields of newly created Test Execution and Tests (components, Test Plan Keys, Labels), you should use the Multipart endpoint. Here you need JSON files similar to the one Jira uses to create new issues, one with the fields of the Test Execution and the other with the fields of the Test. More details here.

Link for related documentation

More details about REST API here.


  • No labels