Creating & Enrolling new students, via API call

Jump to solution
319294
Community Novice

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?

2 Solutions
319294
Community Novice
Author

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 Likes

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