I'm creating a script that goes into all tests into a test execution. I'd like to get the amount of defects for that particular test execution. Is that a way to get it using rest api?
-
Please show what you have tried already and please read, [how-to-ask](https://stackoverflow.com/help/how-to-ask). Is your question related to ruby, the jira api, specs or a rest api. Please add more details. – Christian Sep 03 '19 at 00:32
-
1Hello, sorry for the inconvenience. My question is related to rest api (most specific, x-ray) . I've tried using testrun() /defect but all I get is a 404 error – Brito Sep 03 '19 at 00:57
-
This? https://confluence.xpand-it.com/plugins/servlet/mobile?contentId=27534752#content/view/27534752 maybe you should add the Code or command you have executed. And add jira and / or x-ray tags so that users know what you are using and doing. – Christian Sep 03 '19 at 06:37
-
Api description https://confluence.xpand-it.com/plugins/servlet/mobile?contentId=32804707#content/view/32804707 – Christian Sep 03 '19 at 09:23
-
Hello @Christian, I've tried using this in order to get the defect "/rest/raven/1.0/api/testrun/{id}/defect" but it returns a 404 error using "rest/raven/1.0/api/testexec/
" I can get all the details of the test execution and all the defects opened for each test case . But I cant get the total of defects – Brito Sep 03 '19 at 13:03
2 Answers
Xray enables exporting Cucumber tests to be exported as .feature file that further can be used in your automated tests. To do so use this export endpoint
To import the automated test results back to Jira used this import endpoint
Usually APIs will be executed in conjunction with CI/CD tools, like Jenkins.
In this article you can see that the total number of defects can be view via the Jira UI.
And finally, this video shows how tests are imported and exported via the UI.
Tests can be created via API as well, see here.
I think it all depends on your testplans. When those contain all tests you should be able to execute the test via the endpoint rest/raven/1.0/api/testexec/<testExecution>
.
Maybe it will be good to ask the very same question in the atlassian community.
Sorry for not being able to fully answer your question, but I think you now should have some things to read :)

- 4,902
- 4
- 24
- 42
-
-
-
Hello @Christian, no success yeat Ill try creating a filter using the rest api and retrieve the defects from there... it should work – Brito Sep 09 '19 at 14:09
There is one way that is more straightforward. You can make use of the "Test Execution Defects" custom field, which is a calculated field.
Then you just need to use Jira's REST API and obtain information for the related Test Execution issue, for that specific custom field that returns an array. The number of elements corresponds to the number of defects.
Example of HTTP GET request:
https://sandbox.xpand-it.com/rest/api/2/issue/BOOK-31?fields=customfield_11802
Example of response:
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
"id": "20130",
"self": "https://sandbox.xpand-it.com/rest/api/2/issue/20130",
"key": "BOOK-31",
"fields": {
"customfield_11802": [
"20131"
]
}
}
Another way would be to use the JQL function "defectsCreatedDuringTestExecution ()", as mentioned here: https://docs.getxray.app/display/XRAY/Enhanced+querying+with+JQL Then you could do a Jira REST API search call.
Example of HTTP GET search request using the JQL function: https://sandbox.xpand-it.com/rest/api/2/search?jql=issue%20in%20defectsCreatedDuringTestExecution(BOOK-31)

- 1,777
- 2
- 10
- 12