REST API command

507 views
Skip to first unread message

Joseph Lacey

unread,
Jun 23, 2016, 10:27:41 AM6/23/16
to Canvas LMS Users
Hi,
I was wondering if someone could help me with the following issue.
Right now we are uploading csv files to Canvas. An example of an enrollment file would be:
 

course_id,user_id,role,section_id,status

ABC.2015.FALL.123,111,student,ABC.2015.FALL.123,completed

ABC.2015.FALL.123,222,student,ABC.2015.FALL.123,deleted

 

We want to replace that functionality with REST commands. An example of a command would be:

https://.......instructure...../api/v1/courses/ABC.2015.FALL.123/enrollments?
enrollment[user_id]=111
&enrollment[type]=StudentEnrollment
&enrollment[course_section_id]=ABC.2015.FALL.123
&enrollment[enrollment_state]=active
&access_token=XYZ

 

However that call (executed in Postman (Chrome) rest client) fails with an error - "The specified resource does not exist."

Is it because of the dots in ABC.2015.FALL.123?

I tried escape character %2E, but to no avail.

What am I doing wrong?

 

Thank you very much,

Cody Cutrer

unread,
Jun 23, 2016, 12:59:59 PM6/23/16
to canvas-l...@googlegroups.com
Joseph,

See https://canvas.instructure.com/doc/api/file.object_ids.html. When using an SIS ID with the API, you need to prefix it with the type of ID. For example, you should POST to https://.......instructure...../api/v1/courses/sis_course_id:ABC.2015.FALL.123/enrollments?
enrollment[user_id]=sis_user_id:111
&enrollment[type]=StudentEnrollment
&enrollment[course_section_id]=sis_section_id:ABC.2015.FALL.123
&enrollment[enrollment_state]=active
&access_token=XYZ

Cody Cutrer
Software Engineer
Instructure

--

---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joseph Lacey

unread,
Jun 23, 2016, 2:37:51 PM6/23/16
to Canvas LMS Users
Thank you very much for your response. After making the changes you provided, I still get the same error message. Would you have any other suggestions?
Thanks,

Cody Cutrer

unread,
Jun 23, 2016, 2:42:17 PM6/23/16
to canvas-l...@googlegroups.com
Are you running your own install of Canvas you are running this against? If so, you should look at the Canvas server logs. Or if against Cloud Canvas, do you have the headers from the response? In particular, the X-Request-Context-Id and X-Request-Processor headers will allow me to look up the server logs.

Cody Cutrer
Software Engineer
Instructure

Joseph Lacey

unread,
Jun 23, 2016, 5:27:07 PM6/23/16
to Canvas LMS Users
Hi,
I'm running the script against Cloud Canvas.
This is the Header:

Cache-Control →no-cache

Connection →keep-alive

Content-Encoding →gzip

Content-Length →104

Content-Type →application/json; charset=utf-8

Date →Thu, 23 Jun 2016 21:16:57 GMT

P3P →CP="None, see http://www.instructure.com/privacy-policy"

Server →Apache

Status →404 Not Found

Vary →Accept-Encoding

X-Canvas-Meta →q=976;at=50000000166733;dk=170000000000016;a=85852;g=dA6P7n9KxG6piFzFBU9B6tIDyGGaFu2xidZ90AAj;s=5;c=cluster5;z=us-east-1c;b=1195892;m=1195892;u=0.05;y=0.00;d=0.04;

X-Canvas-User-Id →50000003418119

X-Content-Type-Options →nosniff

X-Rate-Limit-Remaining →700.0

X-Request-Context-Id →aa419be2-126b-47cc-9fb2-1b574e212c90

X-Request-Cost →0.09057744500001136

X-Request-Processor →a023dd3

X-Robots-Tag →none

X-Runtime →0.116450

X-Session-Id →78a92b21ba9948791b490c3ba335d784

X-UA-Compatible →IE=Edge,chrome=1

X-XSS-Protection →1; mode=block

 

When I execute the URL with GET, I get enrolled students, when I execute it wit POST I get "The specified resource does not exist." in the body and status 404 Not Found.

 

Thanks again for your help.

anagp

unread,
Jun 24, 2016, 7:08:59 AM6/24/16
to Canvas LMS Users
Hi, I do not know if it is just because of the example but I noticed that ABC.2015.FALL.123 is used as both a sis_course_id in the url and a sis_section_id in the parameters. This sis_id is probably one or the other. (Eventhough it seems that it is used for both purposes in the csv also) I would try without enrollment[course_section_id]=sis_section_id:ABC.2015.FALL.123

Joseph Lacey

unread,
Jun 27, 2016, 11:24:25 AM6/27/16
to Canvas LMS Users
Thank you Cody, and Anagp for your ideas. Instead of using

/api/v1/courses/:course_id/enrollments

 
commad, I used

POST /api/v1/sections/:section_id/enrollments

with sis_section_id:ABC.2015.FALL.123.
That finely worked! Thanks again!

Randall Anderson

unread,
Jun 27, 2016, 11:32:58 AM6/27/16
to canvas-l...@googlegroups.com
That makes sense as enrollments live in sections not courses...r

--

---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--
Respectfully Serving
--
Randall A. Anderson, M.Ed.
Systems Admin II
ITS
- Academic Services
Maricopa Community Colleges
--
Office: 480.731.8072
--
Cell:  480.580.6471



meshe...@gmail.com

unread,
Jul 25, 2018, 9:13:01 PM7/25/18
to Canvas LMS Users
Hi Joseph, 
I am trying to upload files using the same approach you have used. Could you please explain the process to get the token first? what is the purpose of using redirect url? Since I am planning to upload files using some automation tool there is no point of using redirect url in token generation request? Any idea about the validity of token? 

Many thanks. 

Regards, 
Raju

James

unread,
Jul 27, 2018, 1:42:19 PM7/27/18
to canvas-l...@googlegroups.com
Hi Raju,
It just happens that I'm on vacation right now ('till August 6th). I have no access to our systems and documentation. Off the top of my head I can tell you that our Canvas administrator generates the token in Canvas app, and there is a preference section where you can set your expiration date. We have it set to "never expires" which works fine for our purposes. Unfortunately for more details you have to wait for my return.
Regards,
Jacek.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Canvas LMS Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/canvas-lms-users/O-tgES4IxZk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to canvas-lms-users+unsubscribe@googlegroups.com.

Meshed Group

unread,
Jul 29, 2018, 8:41:41 PM7/29/18
to canvas-l...@googlegroups.com
Hi James, 
Thank you for your response. I found this answer from one of our colleague in this group as well. I have used the manually generated token with expiry date after 20 years. Shouldn't it be enough :) :) ? 

Cheers, 

Regards, 
Raju

--

---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages