0
votes

I am stuck trying to figure out how to authenticate user to access JSON data from JIRA by using the REST api given from this documentation: https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-basic-authentication-6291732/

Items is the array that would allow me to get the values in the JSON data given by the URL from jira.

I am unable to receive the data because it seems to be empty when i print the items variable.

Any help would be appreciated.

    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>
    )
  }
2
Authorization seems correct. Can you also link docs for the endpoint you are hitting please?Matthew Herbst
What do u mean by endpoints, im not really familiar with these terms XDleo jr silao
/rest/api/2/search is the JIRA endpoint that you are hitting in the example aboveMatthew Herbst

2 Answers

0
votes

Try adding the following hearder:

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

jql=project=SUP&maxResults=2 looks off.

Just look at any example:

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)