ucfopen / canvasapi

Python API wrapper for Instructure's Canvas LMS. Easily manage courses, users, gradebooks, and more.
https://pypi.python.org/pypi/canvasapi
MIT License
558 stars 174 forks source link

Support offer and enroll_me parameters for create_course #188

Closed tecoholic closed 6 years ago

tecoholic commented 6 years ago

Environment:

myuser@033517246d6b:/opt$ pip show canvasapi
Name: canvasapi
Version: 0.9.0
Summary: API wrapper for the Canvas LMS
Home-page: https://github.com/ucfopen/canvasapi
Author: University of Central Florida - Center for Distributed Learning
Author-email: techrangers@ucf.edu
License: MIT License
Location: /usr/local/lib/python3.6/site-packages
Requires: pytz, six, requests

myuser@033517246d6b:/opt$ python --version
Python 3.6.5

Code:

course_data = {
  'name': 'Demo Math 101',
  'public_description': 'This is demo course created for demo purposes',
  'license': 'public_domain',
  'default_view': 'assignments',
  'offer': True,
  'enroll_me': True
}

canvas = Canvas(base_url, api_token)
account = canvas.get_account(1)  # admin account
course = account.create_course(course=course_data)

Expected outcome:

A new course created in Canvas which is published and the admin user is is enrolled as the teacher.

Actual outcome:

Course is created, but, neither is the user enrolled as the teacher nor the course is published.

Thetwam commented 6 years ago

Hey @tecoholic!

The offer and enroll_me parameters are separate from the course parameter.

The Canvas API documentation for creating a course calls for course[name] and course[public_description] to set the course's name and description, respectively. This is represented in CanvasAPI by passing a dictionary with keys name and public_description with the keyword course, as you've done in the example provided. offer and enroll_me don't have the course[ prefix, so they should be passed as regular keyword arguments.

This should do the trick:

course_data = {
  'name': 'Demo Math 101',
  'public_description': 'This is demo course created for demo purposes',
  'license': 'public_domain',
  'default_view': 'assignments'
}

course = account.create_course(course=course_data, offer=True, enroll_me=True)

Also, though it shouldn't affect your results, I recommend upgrading your CanvasAPI version to 0.10.0. Gotta get the new stuff!

Please let us know if you have any questions. 😄

tecoholic commented 6 years ago

@Thetwam Thank you for your explanation. Passing the offer and enroll_me as keyword arguments make sense. We will of course be updating to 0.10.0