如何使用Postman从xray Jira Cloud创建GET(REST API)

zsbz8rwp  于 2023-03-18  发布在  Postman
关注(0)|答案(2)|浏览(352)

我的组织有一个Jira Cloud Xray环境,我想在Postman中获得特定测试问题(或多个)的测试步骤。我设法使用Bearer令牌Auth验证执行POST请求,该令牌Auth链接到具有2个代码的请求主体:客户端ID和客户端密码
这个请求的输出是一个令牌,所以我将它存储在一个变量中。
我想我必须使用这个标记来执行GET请求,但是我得到了以下输出:“错误”:“身份验证请求已过期。请尝试重新加载页面。”
我的GET请求的URL如下:https://xray.cloud.getxray.app/api/internal/test/149565/steps?startAt=0&maxResults=8我在问题页面上找到了F12,它有我想要的回应:enter image description here
我错过了什么?

omtl5h9j

omtl5h9j1#

您未使用公共API。documentation中介绍了可用的X射线云API,其中包括REST API和GraphQL API。GraphQL API请求必须经过身份验证,因此您需要向get a token发出初始请求。
public GitHub repository中有一些Postman的集合,展示了如何调用API,还有一个GitHub项目,其中包含源代码片段,比如this one,它精确地显示了您要查找的内容。

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);
});
vx6bjr1n

vx6bjr1n2#

谢谢你@Sérgio我解决了这个问题感谢你的答案.我发送这个graphql查询 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

相关问题