AnsweredAssumed Answered

Is there a way to return only certain fields through an API url request?

Question asked by Michael Salmons on Jun 7, 2018
Latest reply on Jun 15, 2018 by Stuart Ryan

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.

Outcomes