The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
I apologize if this question is very simple but I am new to api, so I am hoping to get an easy answer.
I am trying to automate an api process using Postman to update quiz[lock_at] dates for all courses within a Sub-Account. I have figured out how to do it individually but I am having difficulties defining the property to automate it and move the api from one course to the next, changing the quizzes in the subaccount. Here is what I have in "Tests" for my GET request.
// Parsing the response returned by the request.
var jsonData = pm.response.json();// Extracting the token from the response and setting it as a global variable.
pm.globals.set("newcourse_id", jsonData.course["id"]);
The response I am getting in the Test Results is
There was an error in evaluating the test script: TypeError: Cannot read property 'id' of undefined
I know the issue is with my defining the Canvas Course ID, but I admit I am lost. Any assistance would be great, or if anyone already has a code/collection on how to update all quiz dates in a Sub-Account, that would be great.
Solved! Go to Solution.
Hello Brad,
Thank you for your help. After playing with it with one of our Multi-Media Designers this is how we got it to work.
pm.test("Body contains id", function(){
// Parsing the response returned by the request.
let jsonData = pm.response.json();
console.log('JSON response:', jsonData);
// Extracting the token from the response and setting it as a global variable.
pm.globals.set("newcourse_id", jsonData[0].id);
});
It looks like the jsonData was coming back as an array so we had to point it to that. Logging 'pm.response' was his suggestion too and that is how we uncovered it.
So for anyone who is curious here was the GET:
https://YOURINSTITUTION.instructure.com:CANVASINSTANCEID/api/v1/accounts/ACCOUNTID/courses?page={{current_page}}&per_page=1
Then we had too more requests. One was to Set the Quiz ID. GET:
https://YOURINSTITUTION.instructure.com:443/api/v1/courses/{{newcourse_id}}/quizzes/
With the Tests Script:
pm.test("Body contains id", function(){
// Parsing the response returned by the request.
let jsonData = pm.response.json();
console.log('JSON response:', jsonData);// Extracting the token from the response and setting it as a global variable.
for (let i = 0; i < jsonData.length; i++) {
if (jsonData[i].title == "Final Exam") {
pm.globals.set("quiz_id", jsonData[i].id);
}
}});
Then brought all the information together. So its three requests but a lot faster to automatically change the script. The last piece is just figuring out how to get it to run the three requests.
Thanks for all your help.
Hi Stephen,
Try jsonData.body.course["id"]
A lot of the time the response data is contained in a 'body' attribute.
It could help if you log out the 'pm.response' to see what you're getting back, and what structure the data is in.
Hope that helps!
Hello Brad,
Thank you for your help. After playing with it with one of our Multi-Media Designers this is how we got it to work.
pm.test("Body contains id", function(){
// Parsing the response returned by the request.
let jsonData = pm.response.json();
console.log('JSON response:', jsonData);
// Extracting the token from the response and setting it as a global variable.
pm.globals.set("newcourse_id", jsonData[0].id);
});
It looks like the jsonData was coming back as an array so we had to point it to that. Logging 'pm.response' was his suggestion too and that is how we uncovered it.
So for anyone who is curious here was the GET:
https://YOURINSTITUTION.instructure.com:CANVASINSTANCEID/api/v1/accounts/ACCOUNTID/courses?page={{current_page}}&per_page=1
Then we had too more requests. One was to Set the Quiz ID. GET:
https://YOURINSTITUTION.instructure.com:443/api/v1/courses/{{newcourse_id}}/quizzes/
With the Tests Script:
pm.test("Body contains id", function(){
// Parsing the response returned by the request.
let jsonData = pm.response.json();
console.log('JSON response:', jsonData);// Extracting the token from the response and setting it as a global variable.
for (let i = 0; i < jsonData.length; i++) {
if (jsonData[i].title == "Final Exam") {
pm.globals.set("quiz_id", jsonData[i].id);
}
}});
Then brought all the information together. So its three requests but a lot faster to automatically change the script. The last piece is just figuring out how to get it to run the three requests.
Thanks for all your help.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in