For a class project I am currently working with a professor to access course discussion info programmatically from canvas. To do this I started with testing using curl and then moved to nodejs. I found when making the identical https call through curl and then through nodejs (code snippets below, token removed for privacy), the curl request returned the correct id for the course (127210000000003374) while the nodejs request returned an id incremented by 6 for the course (127210000000003380). Is there something significantly different about how curl requests function from the node https library? Any help would be appreciated, I'm not asking for the answer just to know if there is a header I need to add or anything.
The working curl request (with <insert-token> subbed in)
curl -H "Authorization: Bearer <insert-token>" "https://canvas.instructure.com/api/v1/courses"
The nodeJS request made with the standard library returning wrong id value for courses (with <insert-token> subbed in)
const https = require("https");
const reqHeaders = {
"Authorization": "Bearer <insert-token"
}
const options = {
hostname: "canvas.instructure.com",
port: 443,
path: "/api/v1/courses/",
headers: reqHeaders,
method: "GET"
}
const req = https.request(options, (res) => {
let resString = ""
console.log("response status: " + res.statusCode)
res.on('data', (each) => {
resString += each;
});
res.on('end', () => {
response = JSON.parse(resString);
console.log(response);
})
});
req.end();
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.