canvas-lms icon indicating copy to clipboard operation
canvas-lms copied to clipboard

Course delete/conclude API documentation is incomplete

Open ToeBee opened this issue 10 years ago • 4 comments

The "Conclude a course" API documentation at https://canvas.instructure.com/doc/api/courses.html#method.courses.destroy says that the "event" string is required but the API does not actually require it and seems to default to "delete" if not specified.

Also, the return value of the call is not documented. It seems to be {"delete":true} while other deletion calls (I was just looking at the Assignment deletion one) return the object that was just deleted.

Lastly, it appears to be a soft delete. If you call the delete function twice on the same course, they both return success. If you send a delete request for a course that has never existed, it returns a 404 error.

ToeBee avatar Oct 12 '16 22:10 ToeBee

@ToeBee The event string is required. It is evident from the following piece of code in the CoursesController#destroy if api_request? && !['delete', 'conclude'].include?(params[:event]) return render(:json => { :message => 'Only "delete" and "conclude" events are allowed.' }, :status => :bad_request) end

The response of the delete request returns {"delete": true} if event string is 'delete'. It returns {"conclude": true} if event string is 'conclude'

Almost of the delete requests in Canvas do a soft delete. They change the workflow_state of the resource rather than actually removing the data from the database. When you make a delete request, the code finds the course with the id (including the one whose workflow_state is deleted) and sets it workflow_state again to 'deleted'. In case of a non existing course id, it is unable to find the resource and hence the 404 error.

HTTP DELETE is an idempotent request. But that does not mean it cannot return two different response codes. Idempotent means it leaves the system in the same state. http://stackoverflow.com/questions/6439416/deleting-a-resource-using-http-delete

manish310794 avatar Oct 19 '16 07:10 manish310794

Ah, I am indeed mistaken on the required nature of the event parameter. So the docs are not incorrect.

However they are still incomplete. The return value of the call should be documented. And the soft delete nature of it should probably also be mentioned.

ToeBee avatar Oct 19 '16 15:10 ToeBee

Sorry to have never responded to this @ToeBee, I just pushed up a change to clarify the docs. Most api destroy events are soft-deletes, and a quick looks seems like many api actions don't actually filter to non-deleted objects, so I need to think more about that before changing it. Thanks for the report. I'll link the api docs commit once it's merged.

simonista avatar Nov 09 '17 05:11 simonista

Here's the doc change: 81c4330eaaeda1548902958021ca05afa52b3873

simonista avatar Nov 09 '17 21:11 simonista