uploading a file to Canvas through API

Jump to solution
ksz
Community Novice

I'm trying to perform a post to

POST /api/v1/users/:user_id/files
to upload a profile picture for each student.

I get an exception in the first step as outlined here:

Uploading Files - Canvas LMS REST API Documentation 

exception that I get is:

{"Http Exception occurred when calling Canvas. StatusCode Unauthorized, Url: users/11308/files, Json sent: {\"name\":\"80508_profile_picture.jpg\",\"size\":9361,\"content_type\":\"image/jpeg\"}"}

Method: POST, RequestUri: '<our server address>/api/v1/users/11308/files'

I can do other api calls like get a user, update a users etc. so I know it's not an authentication issue. Why is it giving me an unauthorized error? Currently we show profile pictures in Canvas by supplying a url to an external source. In order to get that to work our servers had to be white listed. Is it the same situation with uploading files? Is there something that needs to be enabled in order for this to work?

Thanks

Labels (1)
0 Likes
1 Solution
pklove
Community Champion

Are you doing this with an admin token?

"Note that typically users will only be able to upload files to their own files section".

So if doing this as an admin, add:

    ?as_user_id=user_id

View solution in original post