0

I'm trying to import an xml report to Jira xRay - to a Test Execution item.

The documentation I can find makes reference to client_id and client_secret, which should be generated by Create API key. Create API key only generates one string, a token.

As such I can't figure out how to use just the token to submit the xml report.

For example, this command:

curl -H "Content-Type: application/json" -X POST --data @"cloud_auth.json" https://xray.cloud.getxray.app/api/v2/authenticate

I can't use it, as it needs client_id and client_secret. Also, the endpoint itself returns

Cannot GET /api/v2/authenticate

.

Using this command:

curl -H "Content-Type: text/xml" -X POST -H "Authorization: Bearer $token" --data @"data.xml" https://xray.cloud.getxray.app/api/v1/import/execution/junit?testExecKey=XNP-23

from: https://docs.getxray.app/display/XRAYCLOUD/Import+Execution+Results+-+REST#ImportExecutionResultsREST-JUnitXMLresults

results in "{"error":"Invalid JWT: JsonWebTokenError: jwt malformed"}"

.

Please can anyone help?

Alichino
  • 1,668
  • 2
  • 16
  • 25

2 Answers2

2

first you need to clarify if you're using Xray on Jira server/datacenter or Jira Cloud, because they are different products and have slightly different APIs; besides Jira Cloud and Jira server/datacenter are also different products. To find out, you can ask your Jira admin for example.

If you’re using Xray Cloud, then this is documentation site. In this case, in order to submit the JUnit XML report you need to make an authencation with a client id and client secret that you obtain on Xray API Keys section. The authentication request is detailed here, and that will return a token that you'll use on the second request. The second request is an HTTP POST, as described here, and you need to pass the token obtained earlier. The main REST API documentation site is this one.

If you’re using Xray on Jira server/datacenter, then this is proper documentation site. In Xray server, the authentication mechanism is provided by Jira itself. You can either use basic authentication or Personal Access Tokens (if you have Jira >= 8.14). This is detailed on Xray server/datacenter page dedicated to its REST API. After choosing the authentication mechanism to use, you just need to make a HTTP POST request as detailed here.

There is an open-source GitHub project with some code snippets, both for Xray server/datacenter and cloud, using different test automation report formats and different authentication mechanisms.

Sérgio
  • 1,777
  • 2
  • 10
  • 12
  • Thanks, Sergio. To obtain the Xray API Key I need to go to Settings->Manage Apps->XRAY-> API KEYS, is this correct? It seems I don't have access to Jira/Xray settings, so would need to get that first. I think this is my main problem here - without the access to Xray API key, I can't get the client_id and the client_secret. I'll ask our admin. PS. We have the Cloud plugin. – Alichino Nov 03 '21 at 13:56
  • You need to as your Jira cloud administrator in order to obtain the client id and client secret (the administrator needs to create one "api key", i.e. client id + client secret pair) – Sérgio Nov 03 '21 at 14:10
  • 1
    Had some problems with the formatting of the JSON but eventually I've figured it out. If anyone also has problems around globbing, or invalid token in JSON, format your JSON like this: "{\"key1\":\"value1\",\"key2\":\"value2\"}" – Alichino Nov 04 '21 at 10:24
  • Wow this was so helpful! – HuserB1989 May 04 '23 at 21:29
0

I have faced the same error when I tried with postman, I have removed " from generated token from start and end position and passed token to API. That resolved this issue

Vasanth
  • 11
  • 2