Is there a way to return only certain fields through an API url request?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to pull simple reports that go beyond Canvas' built-in reports- so I have been working with the API. I have a script I can use to pull what I need, but it's everything- I want to narrow it down to login_id, user_id, and name.
I see that I can deliberately include fields with include[]=fieldname. I don't suppose there's a way to use those additively- that is, only specify the fields I want?
This is the node.js script I am using:
const request = require('request');
let url = 'https://<my domain>.instructure.com:443/api/v1/courses/12/enrollments?type[]=StudentEnrollment&state[]=active&access_token=<my key>&page=5&per_page=100 rel="next"';
request(url, function (err, response, body) {
if(err){
console.log('error:', error);
} else {
let results = JSON.parse(body)
for (var i in results) {
console.log(results[i]);
}
}
});
as you can see I am just manually paging through. If there is way to do this automatically, I would be very interested in that too.
My end goal is a report with the fields mentioned, in a format I could share with instructors.
Any help would be appreciated, thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There should be no need to process anything with PHP if you're using Node.
The API is working as desired, in that a REST API result is a record that sends a predefined set of values back to the requestor. If the API allows filtering the results thats extra. But by default a record contains fields, those fields are being returned. Anything else would be like telling your browser to exclude loading the header or footer from every web page you load... or maybe only from specific sites. But then your browser would have to learn how to take that request and Web sites would have to add that as a feature...
With the links I provided above, you should be able to produce a CSV file with the following headers and values.
course_id, login_id, user_id, name