cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
wuedward
New Member

Context_codes

Jump to solution

Context_codes is required for announcements in the API.  Where can I find context_codes?

Tags (1)
1 Solution
maguire
Community Champion

The context code is simply the string "course_" with the course number appended. For example, I did the following query for my course 11:

I got back:

[ { "id": 4114, "title": "Test announcement 1", "last_reply_at": "2017-03-24T11:45:55Z", "delayed_post_at": null, "posted_at": "2017-03-24T11:45:55Z", "assignment_id": null, "root_topic_id": null, "position": 3, "podcast_has_student_posts": false, "discussion_type": "side_comment", "lock_at": null, "allow_rating": false, "only_graders_can_rate": false, "sort_by_rating": false, "user_name": "Gerald Q. Maguire Jr.", "discussion_subentry_count": 0, "permissions": { "attach": true, "update": true, "reply": true, "delete": true }, "require_initial_post": null, "user_can_see_posts": true, "podcast_url": null, "read_state": "read", "unread_count": 0, "subscribed": false, "topic_children": [], "attachments": [], "published": true, "can_unpublish": false, "locked": false, "can_lock": true, "comments_disabled": false, "author": { "id": 29, "display_name": "Gerald Q. Maguire Jr.", "avatar_image_url": "https://secure.gravatar.com/avatar/52e6e0ae2260166c91cd528ba0c72263?s=50&d=http%3A%2F%2Fpeople.kth.s...", "html_url": "https://kth.instructure.com/courses/11/users/29" }, "html_url": "https://kth.instructure.com/courses/11/discussion_topics/4114", "url": "https://kth.instructure.com/courses/11/discussion_topics/4114", "pinned": false, "group_category_id": null, "can_group": false, "context_code": "course_11", "locked_for_user": false, "message": "<p>This is just a test.</p>\r\n<p> </p>", "subscription_hold": "topic_is_announcement" } ]

Why this formatted string is called a context_code, I do not know.

View solution in original post

6 Replies
maguire
Community Champion

The context code is simply the string "course_" with the course number appended. For example, I did the following query for my course 11:

I got back:

[ { "id": 4114, "title": "Test announcement 1", "last_reply_at": "2017-03-24T11:45:55Z", "delayed_post_at": null, "posted_at": "2017-03-24T11:45:55Z", "assignment_id": null, "root_topic_id": null, "position": 3, "podcast_has_student_posts": false, "discussion_type": "side_comment", "lock_at": null, "allow_rating": false, "only_graders_can_rate": false, "sort_by_rating": false, "user_name": "Gerald Q. Maguire Jr.", "discussion_subentry_count": 0, "permissions": { "attach": true, "update": true, "reply": true, "delete": true }, "require_initial_post": null, "user_can_see_posts": true, "podcast_url": null, "read_state": "read", "unread_count": 0, "subscribed": false, "topic_children": [], "attachments": [], "published": true, "can_unpublish": false, "locked": false, "can_lock": true, "comments_disabled": false, "author": { "id": 29, "display_name": "Gerald Q. Maguire Jr.", "avatar_image_url": "https://secure.gravatar.com/avatar/52e6e0ae2260166c91cd528ba0c72263?s=50&d=http%3A%2F%2Fpeople.kth.s...", "html_url": "https://kth.instructure.com/courses/11/users/29" }, "html_url": "https://kth.instructure.com/courses/11/discussion_topics/4114", "url": "https://kth.instructure.com/courses/11/discussion_topics/4114", "pinned": false, "group_category_id": null, "can_group": false, "context_code": "course_11", "locked_for_user": false, "message": "<p>This is just a test.</p>\r\n<p> </p>", "subscription_hold": "topic_is_announcement" } ]

Why this formatted string is called a context_code, I do not know.

maguire
Community Champion

Details and a python program to do this can be found at Course announcements: Chip sandbox .

maguire
Community Champion

I updated the web page by adding a program that exports the announcements as a spreadsheet - to make them easier to work with. See Course announcements: Chip sandbox 

sonya_corcoran1
Community Contributor

Thanks for sharing.

Originally I was typing "context_codes[]=course_1". Then I read you post and it clicked that I only needed to add "course_1" for the call to work.

0 Kudos
dhagood
New Member

I have a similar question. In other requests I am using a course_id that is five digits long. Like to get discussion posts: /courses/99999/discussion_topics. To pull the announcements I am trying to add the context code, but would that look like this: /announcements?context_codes[]=course_99999? That doesn't work for me. I tried a 1–10 digit number instead, like in the example, and that does return something but it is a status "unauthorized."

maguire
Community Champion

You can see a program for getting course discussions at Course discussions: Chip sandbox  and a program for getting announcements at Course announcements: Chip sandbox