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>
)
}
/rest/api/2/search
is the JIRA endpoint that you are hitting in the example above – Matthew Herbst