Goal: Given a student's name and email address, I'd like to get them added to a course using the Canvas API and Python. For my purposes, either creating a Canvas account for them or sending them an invitation email to self register would be acceptable. I am using a Canvas Free for Teacher account and am the instructor for this course with a valid and working API token.
Problem: I have yet to find the a proper API endpoint and data structure that yield any positive results for either of the two options above. The API documentation is rather vague, and I am unable to find my account ID parameter (perhaps because I'm on a free account?) that would be needed for the request structure in the documentation.
Attempts: I have seen several older threads all with different solutions. For all attempts, here's what my header structure looks like.
api_token = token goes here
c_headers = {
'Authorization': f'Bearer {api_token}'
}Here's what I've tried so far.
The option below yields a 400 response...
url = "https://canvas.instructure.com/api/v1/accounts/self/users"
data = {
'user[name]':'Johnny Doe',
'user[short_name]':'John Doe',
'user[sortable_name]':'Doe, Johnny',
'pseudonym[unique_id]':'johndoe@johndoe.com'
}
response = requests.post(url, headers=c_headers, data=data)...and this one below also returns 400.
url = "https://canvas.instructure.com/api/v1/accounts/self/users"
data = {
'name':'Johnny Doe',
'short_name':'John Doe',
'sortable_name':'Doe, Johnny',
'unique_id':'johndoe@johndoe.com'
}
response = requests.post(url, headers=c_headers, data=data)This option below with a different data structure yields a 500 response.
url = "https://canvas.instructure.com/api/v1/accounts/self/users"
data = {
'user': {
'name': 'Johnny Doe',
'short_name': 'John Doe',
'sortable_name':'Doe, Johnny'
},
'pseudonym': {
'unique_id': 'johndoe@johndoe.com'
}
}
response = requests.post(url, headers=c_headers, data=data)
Ultimately, I just need a solution that I can feed a name and email so that a student will get automatically added or invited to my course once they complete an external registration form, so I am open to other suggestions or workflows that achieve this same result.
Thanks!