0

My organization has a Jira Cloud Xray environment, I want to get test steps of a particular Test issue (or many) in Postman. I managed to authenticate performing a POST request with Bearer token Auth that links to the body of request with 2 codes: client_id and client_secret

The output of this request is one token, so I stored it in a variable.

I think I have to use this token to perform a GET request but I get this output: "error": "Authentication request has expired. Try reloading the page."

The URL of my GET request is the following: https://xray.cloud.getxray.app/api/internal/test/149565/steps?startAt=0&maxResults=8 I found it with F12 on the issue page, it has the response I want: enter image description here

What am I missing?

Harper
  • 1
  • 1

2 Answers2

0

You're not using the public API's. The available Xray cloud APIs are described on the documentation, which includes a REST API and GraphQL API. GraphQL API requests must be authenticated, therefore you'll need to make an initial request to get a token.

There are some collections for Postman, in a public GitHub repository, showcasing how to invoke the APIs. There is also a GitHub project with source-code snippets, such as this one, which shows precisely what you're looking for.

var axios = require('axios');
const { GraphQLClient, gql } = require('graphql-request')

var xray_cloud_base_url = "https://xray.cloud.getxray.app/api/v2";
var xray_cloud_graphql_url = xray_cloud_base_url + "/graphql";
var client_id = process.env.CLIENT_ID || "215FFD69FE4644728C72182E00000000";
var client_secret = process.env.CLIENT_SECRET || "1c00f8f22f56a8684d7c18cd6147ce2787d95e4da9f3bfb0af8f02ec00000000";

var authenticate_url = xray_cloud_base_url + "/authenticate";

// Test issue key to obtain the info from
test_key = "CALC-3"

axios.post(authenticate_url, { "client_id": client_id, "client_secret": client_secret }, {}).then( (response) => {
    console.log('success');
    var auth_token = response.data;

    console.log("AUTH: " + auth_token);

    const graphQLClient = new GraphQLClient(xray_cloud_graphql_url, {
        headers: {
          authorization: `Bearer ${auth_token}`,
        },
      })

      const query = gql` 
      {
        getTests(jql: "key=${test_key}", limit: 1) {
          results {
            issueId
            projectId
    
            jira(fields: ["key", "summary", "description" ])
    
            testType {name}
    
            folder {
                path
            }
    
            steps {
                id
                action
                data
                result
                attachments {
                    id
                    filename
                    downloadLink
                }
                customFields {
                  id
                  name
                  value
                }
            }
    
            scenarioType
            gherkin
    
            unstructured
    
            preconditions(limit: 10) {
              total
              results {
                jira(fields: ["key", "summary"])
              }
            }
          }
        }
    }
    
      
`

    graphQLClient.request(query).then(function(data) {
        console.log(JSON.stringify(data, undefined, 2))
    }).catch(function(error) {
        console.log('Error performing query: ' + error);
    });
}).catch( (error) => {
    console.log('Error on Authentication: ' + error);
});
Sérgio
  • 1,777
  • 2
  • 10
  • 12
  • Hi, I am using REST API and I followed the documentation you linked, in particular REST v1, and I managed to authenticate as written here https://docs.getxray.app/display/XRAYCLOUD/Authentication+-+REST – Harper Mar 16 '23 at 11:47
  • in the documentation it's not written how to make a get, except from Exporting Cucumber Tests: https://docs.getxray.app/display/XRAYCLOUD/Exporting+Cucumber+Tests+-+REST , but what are Cucumber tests? how can I see that my org has cucumber tests? What if I don't have Cucumber studio? – Harper Mar 16 '23 at 11:49
  • Do you want to get the steps of typical manual scripted test cases or the gherkin statements from cucumber tests? what I shared above is for manual tests. The shared code snippet doesnt answer your original question? If not, and since I've provided several resources with concrete examples, what else do you need? Note: Cucumber Test is a type of test having Gherkin statements; if you don't use Cucumber or Gherkin frameworks, you can ignore that – Sérgio Mar 16 '23 at 11:57
  • Thank you, I am almost there. I copied the query starting right after "const query = gql`" and I get this error:{ "errors": [ { "message": "Invalid JQL query", "locations": [ { "line": 3, "column": 9 } ], "path": [ "getTests" ] } ], "data": { "getTests": null } } – Harper Mar 16 '23 at 12:41
0

Thank you @Sérgio I solved the problem thanks to your answer. I send this graphql query on postman:

query
{
  getTests(jql: "key=COL-9791", limit: 1) {
    results {
      issueId
      projectId
    
      jira(fields: ["key", "summary", "description" ])
    
      testType {name}
    
      folder {
        path
      }
    
      steps {
        id
        action
        data
        result
        attachments {
          id
          filename
          downloadLink
        }
        customFields {
          id
          name
          value
        }
      }
    
      scenarioType
      gherkin
    
      unstructured
    
      preconditions(limit: 10) {
        total
        results {
          jira(fields: ["key", "summary"])
        }
      }
    }
  }
}

And used this URL to get request

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Harper
  • 1
  • 1