Use the SIS Term ID with API instead of the Canvas Term ID?

MikeBrinkman
Community Participant

I was wondering if it is possible to use the SIS Term ID with API instead of the Canvas Term ID? I know in user API calls, I can use api/v1/users/sis_user_id: (which isn't documented), I'm hoping that there's a similar undocumented part in the API for using sis_term_id.

My current code:

 

def post_new_course(sci, n, sti):
    api_url = 'https://mycanvasurl:443/api/v1/accounts/1/courses'
    parameters = {
        'course[course_code]': sci,
        'course[sis_course_id]': sci,
        'course[name]': n,
        'course[term_id]': get_canvas_terms(sti)
    }
    result = requests.post(api_url,headers=header,data=parameters).json()

 

To get the term_id, I had to write this ridiculous bit of code:

 

def get_canvas_terms(sti):
    api_url = 'https://mycanvasurl:443/api/v1/accounts/1/terms'
    result = requests.get(api_url,headers=header).json()
    for (i, j) in result.items():
        items = j
        for item in items:
            terms = item
            for (k, v) in terms.items():
                #print (k, v)
                if v == sti:
                    term_id = terms.get('id')
                    print ("Term ID: " + str(term_id))
                    return term_id

 

Obviously this can be tightened up, but I'd like to have a more elegant solution if possible so I can skip this bit. Any suggestions are welcome!

0 Likes
Users who also had this question