How to retrieve most recent test execution results using Xray GraphQL API

I’m working on setting up an automated workflow for Xray Test Executions in Jira Cloud and running into an issue with result ordering.

I’m making a GraphQL call to fetch test execution data like this:

POST Request
Payload: {"query": "{getTestExecutions(jql: \"project = 'DEF' and status = 'ACTIVE'\", limit: 100) {results {issueId}}}"}

The problem I’m facing is that my JQL query returns over 100 test executions, but the API always gives me the oldest ones first. What I actually need are the most recent test executions, typically those from the past week.

I’ve tried a couple of approaches but haven’t had success:

  1. Sorting by creation date - I added ‘order by created DESC’ to my JQL but it didn’t change the result order
  2. Filtering by modification date - I noticed there’s a ‘modifiedSince’ parameter available, but I’m not sure how to use it to limit results to just the past 7 days

Has anyone successfully retrieved the newest test execution records first? Any suggestions on how to properly sort or filter these results would be really helpful.

same issue here with xray graphql! the modifiedSince approach works, but try startedSince if you’re dealing with execution dates instead of creation dates. heads up - the limit can get weird with filtering, so you might need to increase it and handle pagination.

Had this exact same problem with Xray GraphQL ordering - took me weeks to crack it. Xray’s GraphQL completely ignores JQL ordering clauses, which is maddening if you’re used to the regular Jira API. Here’s what actually works: Skip the modifiedSince parameter and put your date filter straight in the JQL instead. Use something like “project = ‘DEF’ and status = ‘ACTIVE’ and created >= -7d” right in your JQL string. This cuts down your dataset before GraphQL even touches it. Then grab the issueId and created timestamp in your results and sort on the client side. JQL date filtering is way more reliable than GraphQL parameters, plus you dodge all the pagination nightmares from huge unfiltered results. Performance is tons better too.

I encountered a similar issue with Xray’s GraphQL API last month. The ordering problem you’re seeing is a known limitation - JQL ordering doesn’t work reliably through their GraphQL interface. I managed to resolve it using the modifiedSince parameter. You need to provide an ISO 8601 datetime string. To target the past week, calculate the date in your code and format it like: {“query”: “{getTestExecutions(jql: "project = ‘DEF’ and status = ‘ACTIVE’", modifiedSince: "2024-01-15T00:00:00Z", limit: 100) {results {issueId created}}}”}. Alternatively, you could retrieve a larger dataset and sort it client-side. While it’s less efficient, it proves to be more reliable. Xray’s GraphQL sorting can be inconsistent compared to standard Jira JQL, so managing the ordering in your application code might be your best bet.