Closed Wolletje01 closed 3 years ago
Hey, would you try the following code?
const response = await fetch("https://somtoday.nl/oauth2/token", {
method: "post",
body: params,
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
const school = await response.json();
console.log(school);
console.log(school.somtoday_api_url); // https://api.somtoday.nl
console.log(school.access_token); // <ACCES-TOKEN>
const leerlingen = await fetch(
school.somtoday_api_url + "/rest/v1/leerlingen",
{ method: "get", headers: { "Content-Type": "application/x-www-form-urlencoded", "Authorization": `Bearer ${school.access_token}` } }
);
const leerling1 = await leerlingen;
console.log(leerling1); // unauthorized
I added the word Bearer
before the token, and replaced URLSearchParams
with a plain object to achieve that.
It works thnx
joe no problem