cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
319294
New Member

Creating & Enrolling new students, via API call

Jump to solution

Good Afternoon,

I'm a developer with a "Free for Teachers" account and I'm quite new to the live API. I was wondering how I would go about creating student accounts with student emails via the live API. From what I understand once this is done I can then do a search for the user's id and then finally enroll the student via his id to the appropriate course

to enroll the student I should use this endpoint?

Tags (3)
2 Solutions

I'm sorry if this is a bit much to ask but would you be able to give me an example of what those requests would look like?  Any language is welcome or just example cURL request... 

I guess I'll show you what I'm doing as well, this returns a 500 error

canvasUrl = "https://canvas.instructure.com/api/v1/accounts/{user_id}/users"
parm = {
     'user' : {
        'name' : 'First Last',
        'short_name' : 'First',
        'terms_of_use' : 1,
        'skip_registration' : 1,
     },
     'pseudonym' : {
        'unique_id''test@gmail.com',
     }
}
response = requests.post(canvasUrl, auth=BearerAuth(teacher_token), data = parm)
print(response)

View solution in original post

0 Kudos

A basic curl example would look like this:

curl -H "Authorization: Bearer <token>" -X POST "https://<domain>.instructure.com/api/v1/accounts/self/users" -F 'pseudonym[unique_id]=danny@instructure.com'‍

I don't remember offhand the data structure, but if I recall the strings represented in the documentation are actually strings and are not representations of JavaScript objects.  Meaning you want your data to actually be something like:

'user[name]': "First Last"

not

{
'user': {
'name': "first last"
}
}

you can search for examples of -d or -f in the all resources page to get a sense.

View solution in original post

4 Replies
tdw
Instructure
Instructure

Hi,  @319294 ‌,

Yes, you are correct.  You can use the "users API" create user method to create the user:

Users - Canvas LMS REST API Documentation 

then you can use the "enrollments API" enroll a user method to enroll the user in a course:

Enrollments - Canvas LMS REST API Documentation 

I'm sorry if this is a bit much to ask but would you be able to give me an example of what those requests would look like?  Any language is welcome or just example cURL request... 

I guess I'll show you what I'm doing as well, this returns a 500 error

canvasUrl = "https://canvas.instructure.com/api/v1/accounts/{user_id}/users"
parm = {
     'user' : {
        'name' : 'First Last',
        'short_name' : 'First',
        'terms_of_use' : 1,
        'skip_registration' : 1,
     },
     'pseudonym' : {
        'unique_id''test@gmail.com',
     }
}
response = requests.post(canvasUrl, auth=BearerAuth(teacher_token), data = parm)
print(response)
0 Kudos

A basic curl example would look like this:

curl -H "Authorization: Bearer <token>" -X POST "https://<domain>.instructure.com/api/v1/accounts/self/users" -F 'pseudonym[unique_id]=danny@instructure.com'‍

I don't remember offhand the data structure, but if I recall the strings represented in the documentation are actually strings and are not representations of JavaScript objects.  Meaning you want your data to actually be something like:

'user[name]': "First Last"

not

{
'user': {
'name': "first last"
}
}

you can search for examples of -d or -f in the all resources page to get a sense.

Thank you! you've been unbelievably helpful! I appreciate you taking the time to help. The second I get my code working I'll append it to this thread so that if someone is to have my same issue they'll be set.