But when I try to make an API request with my access token from https://littlesis.org/api it doesn’t work.
I see that LittleSis wants the string “Littlesis-Api-Token:” but I don’t know how to insert that into the header. All I see in examples is “Bearer XXXXXX”, should that work here? I’ve tried a few things and no avail. Any ideas?
Thanks for the suggestion! It looks like the API he’s using allows you to pass the key via the URL whereas for littlesis you need to do it in a special way.
Here’s a rough example of how to include the API Token in the request header:
function preload() {
let url = 'https://littlesis.org/api/entities/1';
httpDo(
url,
{
method: 'GET',
// Other Request options, like special headers for apis
headers: { 'littlesis-api-token': 'YOUR_TOKEN_HERE'},
mode: 'no-cors',// no-cors, *cors, same-origin
credentials: 'include',// include, *same-origin, omit
redirect: 'follow', // manual, *follow, error
referrer: 'client', // no-referrer, *client
},
function(res) {
console.log(res);
},
function(err) {
console.log(err);
}
);
}
function setup() {
createCanvas(300, 300);
}
function draw() {
}
I am getting CORS related errors and unfortunately unable to provide a quick solution, but I’m sure the more web experienced will provide advice there.
As a hacky backup-plan I can suggest using a basic server side script to cache the request locally so p5.js can access it. (e.g. a node script that receives the same request you would to little-sister, does the request and funnels the message back, but from localhost/same domain the p5 sketch is served from)