【问题标题】:REACTjs basic authentication using REST api for JIRA使用 REST api 进行 JIRA 的 REACTjs 基本身份验证
【发布时间】:2018-09-11 16:53:06
【问题描述】:

我一直在试图弄清楚如何使用本文档中提供的 REST api 验证用户以从 JIRA 访问 JSON 数据:https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-basic-authentication-6291732/

Items 是允许我从 jira 获取由 URL 给出的 JSON 数据中的值的数组。

我无法接收数据,因为当我打印 items 变量时它似乎是空的。

任何帮助将不胜感激。

    this.state = {
      items: []
    }

    var headers = new Headers();
    //test1:test1 is username and password
    headers.append("Authorization", "Basic " + base64.encode("test1:test1"));

    componentDidMount() {
      fetch('http://ksr-ca-qmaltjira.ca.kronos.com:8061/rest/api/2/search?jql=project=SUP&maxResults=2', {headers: headers})
       .then(res => res.json())
       .then(json => {
         this.setState({
           isLoaded: true,
           items: json
         })
       });
    }


  render() {

    var { isLoaded, items } = this.state;
    const emptyOrNot = !!items.length && !!items.length ? <p>not empty</p> : 
    <p>empty</p> //Checks to see if my array of items is empty 

    return (
     {emptyOrNot}
       <div className="App">
         {items.map(item => (
            <li >
                 Name: item.name
            </li>
          )

         )}
       </div>
    )
  }

【问题讨论】:

  • 授权似乎是正确的。您还可以链接您要访问的端点的文档吗?
  • 端点是什么意思,我对这些术语不太熟悉 XD
  • /rest/api/2/search 是您在上面的示例中点击的 JIRA 端点

标签: javascript arrays reactjs jira


【解决方案1】:

尝试添加以下听众:

  headers.append("Content-Type", "application/json");

【讨论】:

  • 你好,我的 items 数组在添加了你所说的内容后似乎仍然是空的
【解决方案2】:

jql=project=SUP&amp;maxResults=2 看着别处。

看看任何例子:

https://yourJIRAurl/issues/?jql=project%20%3D%20"Service%20Desk%20Maintenance"%20

(https://community.atlassian.com/t5/Jira-questions/How-to-create-a-jira-URL-to-do-a-JQL-search/qaq-p/305793)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    相关资源
    最近更新 更多