I'm trying to obtain data from my schools API with Ajax GET request with an API key, but I still get the 401 error message. I have included the API key in the header but it seems to not work.
Here's my code so far;
class App extends Component {
constructor(){
super();
this.state = {
todos:[]
}
}
getTodos(){
$.ajax({
type: "GET",
url: 'https://opendata.seamk.fi/r1/reservation/building/2',
dataType:'json',
headers: {
Authorization: "API_KEY"
},
cache: false,
success: function(data){
this.setState({todos: data}, function(){
console.log(this.state);
});
}.bind(this),
error: function(xhr, status, err){
console.log(err);
}
});
}
componentWillMount(){
this.getTodos();
}
componentDidMount(){
this.getTodos();
}
render() {
return (
<Titles />
<Todos todos={this.state.todos}/>
);
}
}
export default App;
Console message;