Community

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
scottdennis
Community Team
Community Team

All things API

Have a question about the Canvas APIs? Have a cool API integration you'd be willing to share? If so, please post here.

Labels (1)
Tags (1)
271 Replies
garth
Community Champion

To create a peer review you would use the "POST" call.

I will admit I have not personally tested this specific API call.

maguire
Community Champion

The POST API in the form:

https://xyz.test.instructure.com:443/api/v1/courses/:course_id/assignments/:assignment_id/submission...

does not work, it returns:

{
  "errors": [
  {
  "message": "The specified resource does not exist."
  }

  ]
,
  "error_report_id": 82505
}

Response Code

404

Interestingly the GUI to assign a reviewer is using a form action with a URI of the form:

/courses/:course_id/assignments/:assignment_id/peer_reviews/users/:user_id

Where user_id is the assessor and it is passing the reviewee_id as an argument.

If I use the GUI to assign the user, then I can use the API to get the assigned user:

[ { "id": 2833, "user_id": xxx, "asset_id": 60033, "asset_type": "Submission", "workflow_state": "assigned", "assessor_id": yyy, "user": { "id": xxx, "display_name": "xx", "avatar_image_url": "xxxxxx", "html_url": "https://xyz.test.instructure.com/courses/CC/users/xxx" }, "assessor": { "id": yyy, "display_name": "Gerald Q. Maguire Jr.", "avatar_image_url": "yyyyy", "html_url": "https://xyz.test.instructure.com/courses/CC/users/yyy } } ]

Also note that I cannot delete this peer review assignment with the DELETE API:

https://xyz.test.instructure.com:443/api/v1/courses/CC/assignments/A_ID/submissions/xxx/peer_reviews...

{ "errors": [ { "message": "The specified resource does not exist." } ], "error_report_id": 82506 }

Response Code

404
garth
Community Champion

"The specified resource does not exist."

I have received this response in the past when I was using an incorrect resource id, i.e. the wrong assignment id, or the wrong course id, etc.

rlzhang
Community Member

Hello all,

Question regarding to upload new file;

We are to upload some report file to user's File.  I called Canvas uploadfile API passing the file parameters via guideline Uploading Files - Canvas LMS REST API Documentation .   The file was uploaded correctly, but uploaded in the user's default File foder 'unfiled' instead of creating a new folder I defined in 'parent_folder_path' parameter passing in API call,  It used to work correctly creating and uploading the file in a new folder specified in 'parent_folder_path'.    Anyone has idea or experience using the uploadingfile api recently?   

Thanks in advance,

Ruiling

 @rlzhang ,

I remember dealing with the same thing. When working with the user files you need to add an additional folder level.

parent_folder_path=my_files/

then put in the folder name that you want. That change took place a few months back and I don't know that it was ever documented. I figured it out the hard way.

Good luck!

Thanks Kenneth for your reply.  

I tried both add "my_files" or "./my_files" to  parent_folder_path parameter like below. but the file still pulled the file in default "unfiled" folder but not creating new "testfolder" .  Is it "my_files" a static foldername?  Thanks!

array(4) {

  'name' =>

  string(50) "mytestfile.pdf"

  'size' =>

  int(228394)

  'parent_folder_path' =>

  string(20) "my_files/testfolder"

  'content_type' =>

  string(15) "application/pdf"

}

When you are looking at the user's files, you see a folder for the different courses they are enrolled in and in that list there is a "my_files" folder. Your "testfolder" should be inside that folder with the file in it. In my use case I am using a folder called "images" and this is what it ends up looking like:

Screen Shot 2016-12-05 at 3.01.03 PM.png

garth
Community Champion

Did you make the call to get the sub-folder id?

Thanks Kenneth,  We have similar file structure as yours, but we don't have sub_folder 'my_files'.  but even though I manually add the folder 'my_files' under root folder My Files, then pass in the parent_folder_path="my_files/test".   after uploadfile api call, the new folder 'unfiled' is created, and the file is uploaded in 'unfiled' folder, while not in the expected my_files folder.

Screen Shot 2016-12-06 at 11.54.15 AM.png

Here below is the cUrl I used to call the API:

$ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url );  //url for api/v1/users/{id}/files

        curl_setopt ($ch, CURLOPT_HTTPHEADER, $tokenHeader);//Authorization

        curl_setopt($ch, CURLOPT_POST, count($fields));   // TRUE

        curl_setopt($ch, CURLOPT_POSTFIELDS, $step1_params);

//step1_params :name=test.pdf&size=228394&parent_folder_path=test&content_type=application%2Fpdf"

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // capture the response to a variable

        $response = curl_exec($ch);

        curl_close($ch);

What does the upload_params look like in your uploadfile api call response?   One place I noted in the upload_params on my response, the key is indicated under ../attachments/,  but canvas API document give sample response result as ""key": ".../files/testfile". but not sure if related.   

array(9) {

  'AWSAccessKeyId' =>string(20) "testid"

  'Filename' => string(50) "test.pdf"

  'key' =>string(96) "account_45110000000000001/attachments/2308001/test.pdf"

...}

Thanks!

Ruiling

rlzhang
Community Member

No Garth.  I didn't pass sub folder id,  my understanding  the passing parent_folder_path would created if  doesn't exist. according to canvas fileupload api guidedoc:

"parent_folder_path: The path of the folder to store the file in. The path separator is the forward slash `/`, never a back slash. The folder will be created if it does not already exist. This parameter only applies to file uploads in a context that has folders, such as a user, a course, or a group. If this and parent_folder_id are sent an error will be returned. If neither is given, a default folder will be used"