cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Member

Why Create Course with API Returns 404

Jump to solution

course‌

Hi,

I'm attempting to create a course using this api from within Postman: 

POST /v1/accounts/{account_id}/courses 

Request JSON

{
"course": {
"name" : "API Development Test in Postman Term Test",
"course_code" : "1",
"start_at" : "2020-09-27T11:43:36.174Z",
"end_at" : "2020-10-27T11:43:36.174Z",
"license" : "private",
"is_public" : true,
"is_public_to_auth_users" : false,
"public_syllabus" : true,
"public_syllabus_to_auth" : false,
"public_description" : "This course will help you to learn how to create APIs using Java.",
"allow_student_wiki_edits" : false,
"allow_wiki_comments" : true,
"allow_student_forum_attachments" : true,
"open_enrollment" : true,
"self_enrollment" : true,
"restrict_enrollments_to_course_dates" : true,
"hide_final_grades" : true,
"apply_assignment_group_weights" : true,
"time_zone" : "Asia/Kolkata",
"default_view" : "feed",
"syllabus_body" : "This is dummy syllabus body",
"term_id": "1"
"offer" : true,
"enroll_me" : true,
"enable_sis_reactivation" : false
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The response is:

{
    "errors": [
        {
            "message""The specified resource does not exist."
        }
    ]
}
However, if I changed the request JSON to skip term_id:
{
"course": {
"name" : "API Development Test in Postman Term Test",
"course_code" : "1",
"start_at" : "2020-09-27T11:43:36.174Z",
"end_at" : "2020-10-27T11:43:36.174Z",
"license" : "private",
"is_public" : true,
"is_public_to_auth_users" : false,
"public_syllabus" : true,
"public_syllabus_to_auth" : false,
"public_description" : "This course will help you to learn how to create APIs using Java.",
"allow_student_wiki_edits" : false,
"allow_wiki_comments" : true,
"allow_student_forum_attachments" : true,
"open_enrollment" : true,
"self_enrollment" : true,
"restrict_enrollments_to_course_dates" : true,
"hide_final_grades" : true,
"apply_assignment_group_weights" : true,
"time_zone" : "Asia/Kolkata",
"default_view" : "feed",
"syllabus_body" : "This is dummy syllabus body"
},
"offer" : true,
"enroll_me" : true,
"enable_sis_reactivation" : false
}
Then, a course is created but the course name and code are persisted but term is not set:

{
"id": 1392070,
"root_account_id": 228,
"enrollment_term_id": 88,
"restrict_enrollments_to_course_dates": true,
"start_at": "2020-09-27T11:43:36Z",
"account_id": 18135,
"uuid": "YyHCpkW0K41CoMSShZNAPtgSTVbpnljCeRb73YjG",
"name": "API Development Test in Postman Term Test",
"grading_standard_id": null,
"is_public": true,
"created_at": "2020-05-14T13:08:37Z",
"allow_student_forum_attachments": true,
"course_code": "1",
"default_view": "feed",
"open_enrollment": true,
"allow_wiki_comments": true,
"self_enrollment": true,
"license": "private",
"public_description": "This course will help you to learn how to create APIs using Java.",
"grade_passback_setting": null,
"end_at": "2020-10-27T11:43:36Z",
"public_syllabus": true,
"public_syllabus_to_auth": false,
"storage_quota_mb": 50000,
"is_public_to_auth_users": false,
"hide_final_grades": true,
"apply_assignment_group_weights": true,
"calendar": {
"ics": "https://<our host>/feeds/calendars/course_YyHCpkW0K41CoMSShZNAPtgSTVbpnljCeRb73YjG.ics"
},
"time_zone": "Asia/Kolkata",
"blueprint": false,
"sis_course_id": null,
"sis_import_id": null,
"integration_id": null,
"workflow_state": "available"
}

 

What is the proper request JSON?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Highlighted

Yes, I did leave it out by accident but had it in my request data. 

I finally figured out my error.  The term_id was throwing the 404 because I was setting it to a non-existent term.  Once I've removed that field from the request body, I was able to create a course successfully.

Wish the error was a bit more precise as far as what resource was non-existent in the 404 message.  Something like term_id returns null would be extremely helpful.

Thank you James and David for jumping in so quickly!

Thanks,
Janice

View solution in original post

0 Kudos
3 Replies
Highlighted
Adventurer

term id is not a string, it's a number. From /api/v1/accounts/1/terms

{
"id": 1,
"name": "Default Term",
"start_at": null,
"end_at": null,
"created_at": "2018-06-27T14:50:20Z",
"workflow_state": "active",
"grading_period_group_id": null,
"sis_term_id": null,
"sis_import_id": null
}
Highlighted
Navigator

cluemyeein@gmail.com 

I don't know if it was a copy/paste error or something else, but you don't have a comma between term_id and offer.

Make sure you have a term_id of 1. When I try this post with a term ID that I don't have permission to access (I made up a number that isn't ours), I got the same error you got.

The API documentation says "All integer ids in Canvas are 64 bit integers. String ids are also used in Canvas" and allows to force integer IDS as strings. That made it seem unreasonable that you would need to avoid the quotes.

To confirm, I did just now create a course with a minimal amount of information. Code 13107 is for our Summer 2020 term. Note that in the call, I did put quotes around it.

{
"course": {
"name": "Test Course for Janice",
"term_id": "13107"
}
}

Notice the quotes around the "13107"

The response from Canvas included "enrollment_term_id": 13107,

When I went to the course that was created and looked at the settings, it was there.

347604_pastedImage_1.png

I would use the GET /api/v1/accounts/self/terms call to double check your term_id.

Highlighted

Yes, I did leave it out by accident but had it in my request data. 

I finally figured out my error.  The term_id was throwing the 404 because I was setting it to a non-existent term.  Once I've removed that field from the request body, I was able to create a course successfully.

Wish the error was a bit more precise as far as what resource was non-existent in the 404 message.  Something like term_id returns null would be extremely helpful.

Thank you James and David for jumping in so quickly!

Thanks,
Janice

View solution in original post

0 Kudos