Community

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
yaach
Community Member

Get term id based on sis_term_id

Any hints how to get a term_id based on the sis_term_id? I need to place a course in a specific term, but I need the term id and I only have the sis_term_id. FYI, adding course through COURSE API.

Thanks

Labels (5)
Tags (1)
8 Replies
MattHanes
Community Champion

You actually can use the sis_term_id in your API calls. The details about that can be found here: Object IDs, SIS IDs, and special IDs - Canvas LMS REST API Documentation 

Basically instead of putting the term ID in the API call you just add "sis_term_id:" in front of the SIS term ID in the API call.

yaach
Community Member

Hi Matt,

Yes, I already tried that, but I dont get any results:

http://mydomain/api/v1/accounts/1/terms/sis_term_id:1234

I am trying to create a course using

http://mydomain/api/v1/accounts/1/courses/

together with the post parameters, one of them being term_id, not sis_term_id.

MattHanes
Community Champion

I don't think there is a GET call for a specific term, but you can get all the terms and show the term ID that you need for creating the course by using the https://mydomain/api/v1/accounts/1/terms/ call. 

yaach
Community Member

I know, then loop till I find a match for the sis_term_id. Wish there could be a direct call.

Thanks

pklove
Community Champion

If you really did need to get the id, rather than using sis_term_id:termid in its place, a workaround instead of getting all terms is to do an update (PUT) using sis_term_id:termid  and the term name.  The update returns a term object which has the id in it.

Eg:

curl $server/api/v1/accounts/1/terms/sis_term_id:NK1 \
-X PUT \
-F "enrollment_term[name]=NK One" \
-H "Authorization: Bearer $token"

will return

{"id":35,"name":"NK One", ....

MattHanes
Community Champion

One more thing, when I create courses using the API, I always send it as a JSON object. Here is an example of the JSON object to send if I want to use the sis_term_id:

{
    "course":
        {
            "name": "Multicultural Literature",
            "course_code": "23.X670",
            "sis_course_id": "23.X670T16-17",
            "term_id": "sis_term_id:FY-16-17"
        }
      
}
yaach
Community Member

ok ok, that's different, didn't know about that trick. I will give it a try.

yaach
Community Member

ok, just confirming key:value value for key term_id works.