I'm new to APIs and I'm not able to implement a callback to add the elements of an array, ie make a post. I have a submit button that when clicked should read the array and add all the notes to the corresponding students. I have the array students and gradeValue. My addGradeToUsers function does POST, but I can not get it to run 3 times when I click on the submit button. How do I resolve this?
function addGradeToUsers(student, gradeValue){
showData();
var orgUnitId= 167877; //course number
var gradeObjectId =111321; //grade name
document.getElementById("PUTField").checked = true;
document.getElementById("actionField").value = "/d2l/api/le/1.0/"+ orgUnitId +"/grades/"+ gradeObjectId+ "/values/"+ student +"";
document.getElementById("dataField").value = "{\n \"Comments\":{\"Content\":\"null\",\"Type\":\"Text\"},\n \"PrivateComments\":{\"Content\":\"null\",\"Type\":\"Text\"},\n \"GradeObjectType\": 1,\n\"PointsNumerator\":"+gradeValue+" \n}";
}
function addGrade(student, gradeValue, callback)
{
var students = [58686,58687, 392854]; // user Ids
var gradeValues= [34,10,33];
for(var i=0; i< students.length; i++){
student=students[i];
gradeValue=gradeValues[i];
callback(student, gradeValue);
}
}
Here my submit button:
<div class="form-group">
<label for='contentType'>Importar Notas</label>
<input class="btn btn-default" type="button" value="Add Grade to Users" onclick='addGrade(addGradeToUsers(58687,10))'>
</div>