- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022
10:03 AM
Hello @MikeBrinkman
If you make the following update, you should be able to eliminate the need for the second function to get the Canvas term id based on the SIS term id. This worked for me when I tested it using the format for the sis_term_id
import json
def post_new_course(sci, n, sti):
api_url = 'https://mycanvasurl:443/api/v1/accounts/1/courses'
parameters = json.dumps({
"course": {
"course_code": sci,
"sis_course_id": sci,
"name": n,
"term_id": f"sis_term_id:{sti}"
}
})
result = requests.post(api_url,headers=header,data=parameters).json()
I'm not sure how you have your header defined, but with the above format, you will need to include the following in the header too since it is using JSON format for the payload (https://canvas.instructure.com/doc/api/index.html
'Content-Type': 'application/json'