API Calls via HTML Iframe

adrfelipe
Community Member

I am a Canvas LMS manager at my company and we are creating NPS forms for courses. This form the student will be able to vote from 0 to 10 and give a justification of his vote, this is the only information he inserts. We also want some information about the student, such as name, ID, course and among others that he does not need to fill in, but rather access this type of information through the API. This form would be an HTML within the course that is downloaded by an iframe within a course page.

 

The way we are doing it today is a javascript function that is loaded by the js file that is inside the subaccount theme. This is the code that is inside the js file of the subaccount theme, the user is the object that the API call returns and the user.id would be the user ID of the session. This is already working

function getId() {
    $.getJSON("/api/v1/users/self?include[]=uuid", "keys=id", function (data) {
        var user = data;
        console.log(user.id);
        window.onload = function () {
            var frame = document.getElementById('M3').contentWindow;
            frame.postMessage(user.id, "*");
        }
    });
}

 

Is there any way I can access thus user.id in an HTML file loaded by an iframe inside a course page, so that the form can read and send this information to the answer sheet?

0 Likes