Discussions
Requesting data from Haiilo API demo
Hello, im trying to develop a plugin which requests data from api/users as a json and renders it.
What is the best way to get all of the data from there? The plugin itself is hosted on Netlify.
What steps should i follow to get the data?
If you can provide a demo/example for this kind of plugin thats making API requests, it would be great.
fetch('.....com/web/authorization/token', { credentials: 'include' })
.then(r => r.json())
.then(console.log)
.catch(console.error);
and then send a fetch request using the token from above:
fetch('.../api/users', {
headers: {
'Authorization': 'Bearer ...'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
I get all of the data shown in the console. When i try to fetch the token from my plugin, i get a much smaller one and the fetch /api/users gives me an internal server error since the token is incorrect.
Also, if you have any suggestions how to work around CORS errors , that would be great.