Forum Discussion
Hi Roger, I'm happy to take a look if you are happy to share a file privately. It's fine to omit the API key, but I can check your implementation to see if I can spot anything obvious. I'm no expert in this area, but I have worked with a lot of APIs and so do have some understanding of what is required for them to work. I do enjoy solving this stuff too, if I have the time!
I also found this online documentation that may help? https://www.talentlms.com/pages/docs/TalentLMS-API-Documentation.pdf
- RogerHernandez-2 years agoCommunity Member
HI Sam,
Thanks for offering to help.
Sorry for the late response I forgot where I posted this when i last saw your response. My mind is getting old and forgetful.(ha)
Here is the code. I probably am missing one tiny element.
This was all extrapolated from Postman.
ar myHeaders = new Headers();
myHeaders.append("Authorization", "Basic {apikey}==");
var raw = "";
var requestOptions = {
method: 'GET',
mode: 'cors',
headers: myHeaders,
};
fetch("https://dsi.talentlms.com/api/v1/addusertogroup?user_id=8&group_key={groupkey}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));Here is the console error once the javascript fires. No console errors other wise.
Access to fetch at 'https://dsi.talentlms.com/api/v1/addusertogroup?user_id=8&group_key=AFydWOsHF' from origin 'https://cdn.talentlms.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.