Zapi API - 出现错误期望声明“qsh”具有价值

问题描述 投票:0回答:3

我只是尝试从 zapi api 获取一般信息,但出现错误 预计声明“qsh”的值为“7f0d00c2c77e4af27f336c87906459429d1074bd6eaabb81249e1042d4b84374”,但它的值为“1c9e9df281a969f497d78c7636abd8a20b3353” 1a960e5bd92da0c725e9175de9'

API 链接:https://prod-api.zephyr4jiracloud.com/connect/public/rest/api/1.0/config/generalinformation

任何人都可以帮助我吗?

selenium jira jira-zephyr
3个回答
2
投票

查询字符串参数必须按字母顺序排序,这将解决问题。
请参阅此链接以供参考:
https://developer.atlassian.com/cloud/bitbucket/query-string-hash/


2
投票

我绝对可以帮助你。您需要以正确的方式生成 JWT 令牌。

package com.thed.zephyr.cloud.rest.client.impl;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.thed.zephyr.cloud.rest.ZFJCloudRestClient;
import com.thed.zephyr.cloud.rest.client.JwtGenerator;

public class JWTGenerator {

                public static void main(String[] args) throws URISyntaxException, IllegalStateException, IOException {
                                String zephyrBaseUrl = "https://prod-api.zephyr4jiracloud.com/connect";

                                String accessKey = "TYPE YOUR ACCESS KEY-GET IT FROM ZEPHYR";
                                String secretKey = "TYPE YOUR SECRET KEY-GET IT FROM ZEPHYR";
                                String userName = "TYPE YOUR USER - GET IT FROM ZEPHYR/JIRA";

                                ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName).build();
                                JwtGenerator jwtGenerator = client.getJwtGenerator();

                                String createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycles/search?versionId=<TYPE YOUR VERSION ID HERE>&projectId=<TYPE YOUR PROJECT ID HERE>";

                                URI uri = new URI(createCycleUri);
                                int expirationInSec = 360;
                                String jwt = jwtGenerator.generateJWT("GET", uri, expirationInSec);
                                //String jwt = jwtGenerator.generateJWT("PUT", uri, expirationInSec);
                                //String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec);

                                System.out.println("FINAL API : " +uri.toString());
                                System.out.println("JWT Token : " +jwt);    

                }
 }

还克隆此存储库:https://github.com/zephyrdeveloper/zfjcloud-rest-api,它将为您提供相应编码所在的所有方法。您可以构建一个 Maven 项目来直接导入这些依赖项。

*我也花了很多天的时间来弄清楚,所以要有耐心,这只是你生成正确的 JWT 的时间。


0
投票

显然,导致此错误的原因是您没有为尝试调用的特定 API 端点(包括参数)生成 JWT 令牌。这意味着,对于您进行的每次调用,您都需要不同的特定令牌,因此,即使您调用相同的 API 但每次发送不同的参数,那么您也需要使用这些参数为该 API 提供 JWT。

也就是说,我在这里找到了一个可能的替代方案:

https://support.smartbear.com/zephyr-squad-cloud/docs/en/rest-api/generate-api-access-token.html?sbsearch=jwt

© www.soinside.com 2019 - 2024. All rights reserved.