Every API is different, there’s no single way to provide an API key. It’s up to the designer of the API. So we can’t tell if your code fetches the JSON as intended unless you share a link to the API documentation.
I’m suspicious that httpDo(), httpGet() & httpPost() don’t take advantage of preload().
Therefore the execution can reach setup() & even draw() and the loading isn’t finished yet!
That’s why your console.log(spid[0]); fails, b/c spid[] array hasn’t been initialized by the success callback function (res) { spid = res; } within httpDo().
According to the httpDo()'s example you seem to be doing it right by including a headers property:
But given I don’t have your API Key, I’ve written a sketch to get the file “spid.json” via a CDN proxy.
In console, I get error
“Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.”
I think this is the reason that the download has failed
I google it and now I know that this is the problem of CORS policy but I can’t find the solution of this.
let spid;
function preload() {
spid = loadJSON('https://static.api.nexon.co.kr/fifaonline4/latest/spid.json');
}
function setup() {
console.log(spid[0]);
}