This document will help to configure (enable/disable) discussion forum for any of the learning process
(i.e. groups, course, textbook, etc.)
For Groups:
Enabling discussion forums for groups will be done via UI.
Now to call the create forum API, first, we need to configure a form API that will respond back the request payload for creating the forum.
Step: 1
Configure form API:
Endpoint:
POST: {{host}}/data/v1/form/create
Request payload:
{ "request": { "type": "forum", "subType": "group", "action": "create", "data": { "templateName": "defaultTemplate", "action": "create", "fields": [ { "category": { "name": "General Discussion", // Forum name "pid": "15", // parent category id, under this category, new forum will be creted. it will be a root category. "uid": "1", // admin user id "description": "", "context": [ { "type": "group", "identifier": "_groupId" // to be replaced form client side with actul group id. } ] } } ] } } }
Once created, this form API will be called from the client-side.
Endpoint:
POST: {{host}}/data/v1/form/read
Request payload:
{ "request": { "type": "forum", "subType": "group", "action": "create" } }
Response:
{ "id": "api.form.read", "params": { "resmsgid": "095168d1-b6d6-4f1c-ae0f-d8e1dbed7122", "msgid": "64b92bb4-636a-449b-8c57-a2b91fc315fb", "status": "successful" }, "responseCode": "OK", "result": { "form": { "type": "forum", "subtype": "group", "action": "create", "component": "*", "framework": "*", "data": { "templateName": "defaultTemplate", "action": "create", "fields": [ { "category": { "name": "General Discussion", "pid": "15", "uid": "1", "description": "", "context": [ { "type": "group", "identifier": "_groupId" } ] } } ] }, "created_on": "2021-02-15T05:33:03.734Z", "last_modified_on": "2021-02-15T09:52:41.820Z", "rootOrgId": "*" } }, "ts": "2021-03-05T10:01:51.700Z", "ver": "1.0" }
NOTE: the context identifier should be replaced from the client-side with actual group_id before calling the “forum create” API. So, in basic words, this form response will work as a request payload for the actual forum create API.
Step 2:
Call the create forum API :
Endpoint:
POST: {{host}}/discussion/forum/v3/create
Request payload:
{ "category": { "name": "General Discussion", "pid": "30", "uid": "4", "description": "", "context": [ { "type": "group", "identifier": "95502931-e903-45e0-a4f7-f6ae3c97a66f" } ] } }
Response:
{ "id": "api.forum.v3.create", "ver": "1.0", "ets": 1614939498392, "params": { "resmsgid": "4739650a-cd23-43ce-9634-0e864d243eba", "msgid": "", "status": "Success" }, "responseCode": "OK", "result": { "forums": [ { "sbType": "95502931-e903-45e0-a4f7-f6ae3c97a66f", "sbIdentifier": "95502931-e903-45e0-a4f7-f6ae3c97a66f", "newCid": 93, "cids": [ 93 ] } ] } }
For courses:
Till now, a Discussion forum for courses can be configured via APIs only.
Below APIs will be used to configure a discussion forum for any of the courses.
Step 1:
Create a parent category. This category id will be used as the root pid
Endpoint:
POST: {{host}}/discussions/api/v2/categories?_uid=1
Request body:
{ "name": "Course: Parent category " }
Response:
{ "code": "ok", "payload": { "cid": 7, // this cid will used as pid for the next et of apis "name": "Course: Parent category ", "description": "", "descriptionParsed": "", "icon": "", "bgColor": "#86C1B9", "color": "#333", "slug": "7/course-parent-category", "parentCid": 0, "topic_count": 0, "post_count": 0, "disabled": 0, "order": 7, "link": "", "numRecentReplies": 1, "class": "col-md-3 col-xs-6", "imageClass": "cover", "isSection": 0 } }
Step 2:
Take the above created CID and make the create forum API call for course:
Endpoint:
POST: {{host}}/discussion/forum/v3/create
Request Body:
{ "category": { "name": "Discussion forum for course", "pid": "7", // parent category (take the cid form the above api response) "uid": "1", // admin user id "description": "", "context": [ { "type": "course", "identifier": "_courseId" // to be replaced by actual Course_id } ], "privileges": { "copyFromCategory": "134" // dummy category with course level privileges } } }
Response:
{ "id": "api.forum.v3.create", "ver": "1.0", "ets": 1614939498392, "params": { "resmsgid": "4739650a-cd23-43ce-9634-0e864d243eba", "msgid": "", "status": "Success" }, "responseCode": "OK", "result": { "forums": [ { "sbType": "course", "sbIdentifier": "do_1234", "newCid": 8, "cids": [ 8 ] } ] } }
Step: 3
After creating course level category, we have to create batch level category. For the batch level also we are using same api (forum create).
End Point
POST: {{host}}/discussion/forum/v3/create
Note: Take the newCid
value from the above response.
Request Body
{ "category": { "name": "Discussion forum for Batch", "pid": "8", // parent category (take the cid form the above api response) "uid": "1", // admin user id "description": "", "context": [ { "type": "batch", "identifier": "_batchId" // to be replaced by actual batch_id } ], "privileges": { "copyFromCategory": "134" // dummy category with batch level privileges }, "subcategories": [ { "name": "Annoucements", "description": "", "privileges": { "copyFromCategory": "120" // dummy category with batch level privileges (for anouncement) } }, { "name": "General discussions", "description": "", "privileges": { "copyFromCategory": "121" // dummy category with batch level privileges (for GD) } } ] } }
Response
{ "id": "api.forum.v3.create", "ver": "1.0", "ets": 1614939498392, "params": { "resmsgid": "4739650a-cd23-43ce-9634-0e864d243eba", "msgid": "", "status": "Success" }, "responseCode": "OK", "result": { "forums": [ { "sbType": "batch", "sbIdentifier": "batchId", "newCid": 9, "cids": [ 9 ] } ] } }
Some Usfull Apis:
Access the groups and group users attached to a category.
End Point
{{host}}/discussions/api/forum/v3/groups/users
Request Body
{ "request": { "cid": 255, "groups": ["Course Mentor", "kvn_001"] // optional } }
Response
{ "id": ".api.forum.v3.groups.users", "ver": "1.0", "ets": 1615210872732, "params": { "resmsgid": "5c9755e2-9aeb-4efd-aae1-c347803bbe48", "msgid": "", "status": "Success" }, "responseCode": "OK", "result": { "groups": [ { "name": "Global Moderators", "members": [] }, { "name": "guests", "members": [] }, { "name": "spiders", "members": [] }, { "name": "registered-users", "members": [ { "uid": 24, "userName": "vvaanqqeeeqnuuydddy", "sbUid": "1122311135656333w" }, { "uid": 9, "userName": "venkat002", "sbUid": "efgh_5678" }, { "uid": 8, "userName": "venkat001", "sbUid": "abcd_1234" }, { "uid": 7, "userName": "ven1", "sbUid": null }, { "uid": 6, "userName": "venkat-group 0", "sbUid": null }, { "uid": 5, "userName": "venkat-test", "sbUid": null }, { "uid": 4, "userName": "testUser", "sbUid": null }, { "uid": 3, "userName": "Vinu", "sbUid": null }, { "uid": 26, "userName": "dsbfjdsf", "sbUid": "45454646461112333" }, { "uid": 25, "userName": "fsbmbgbfsgs", "sbUid": "4545464646" }, { "uid": 23, "userName": "vvaanqqeeeqnuuyy", "sbUid": "112231113565633" }, { "uid": 22, "userName": "vvaanqqeeeqn", "sbUid": "11223111333" }, { "uid": 21, "userName": "vvaanqqqn", "sbUid": "112231113" }, { "uid": 2, "userName": "venkat", "sbUid": null }, { "uid": 17, "userName": "test-venkat-22", "sbUid": "abcd_12342222211q2332322222" }, { "uid": 16, "userName": "test-venkat-2", "sbUid": "abcd_12342222211q233232" }, { "uid": 15, "userName": "test-venkat-1", "sbUid": "abcd_12342222211q2" }, { "uid": 20, "userName": "vvaann", "sbUid": "112233" }, { "uid": 19, "userName": "venkat-btech", "sbUid": "12f61a0248" }, { "uid": 18, "userName": "ntptest104", "sbUid": "8454cb21-3ce9-4e30-85b5-fade097880d8" }, { "uid": 1, "userName": "admin", "sbUid": null }, { "uid": 14, "userName": "test-venkat", "sbUid": "abcd_123422222" }, { "uid": 13, "userName": "PublicUser", "sbUid": null }, { "uid": 12, "userName": "Mentor", "sbUid": null }, { "uid": 11, "userName": "venkat00342343", "sbUid": "efgh_56785454333" }, { "uid": 10, "userName": "venkat00342", "sbUid": "efgh_56785454" } ] }, { "name": "verified-users", "members": [ { "uid": 1, "userName": "admin", "sbUid": null } ] }, { "name": "unverified-users", "members": [ { "uid": 9, "userName": "venkat002", "sbUid": "efgh_5678" }, { "uid": 8, "userName": "venkat001", "sbUid": "abcd_1234" }, { "uid": 4, "userName": "testUser", "sbUid": null }, { "uid": 26, "userName": "dsbfjdsf", "sbUid": "45454646461112333" }, { "uid": 7, "userName": "ven1", "sbUid": null }, { "uid": 6, "userName": "venkat-group 0", "sbUid": null }, { "uid": 5, "userName": "venkat-test", "sbUid": null }, { "uid": 3, "userName": "Vinu", "sbUid": null }, { "uid": 25, "userName": "fsbmbgbfsgs", "sbUid": "4545464646" }, { "uid": 24, "userName": "vvaanqqeeeqnuuydddy", "sbUid": "1122311135656333w" }, { "uid": 23, "userName": "vvaanqqeeeqnuuyy", "sbUid": "112231113565633" }, { "uid": 2, "userName": "venkat", "sbUid": null }, { "uid": 16, "userName": "test-venkat-2", "sbUid": "abcd_12342222211q233232" }, { "uid": 22, "userName": "vvaanqqeeeqn", "sbUid": "11223111333" }, { "uid": 21, "userName": "vvaanqqqn", "sbUid": "112231113" }, { "uid": 20, "userName": "vvaann", "sbUid": "112233" }, { "uid": 19, "userName": "venkat-btech", "sbUid": "12f61a0248" }, { "uid": 18, "userName": "ntptest104", "sbUid": "8454cb21-3ce9-4e30-85b5-fade097880d8" }, { "uid": 17, "userName": "test-venkat-22", "sbUid": "abcd_12342222211q2332322222" }, { "uid": 15, "userName": "test-venkat-1", "sbUid": "abcd_12342222211q2" }, { "uid": 14, "userName": "test-venkat", "sbUid": "abcd_123422222" }, { "uid": 13, "userName": "PublicUser", "sbUid": null }, { "uid": 12, "userName": "Mentor", "sbUid": null }, { "uid": 11, "userName": "venkat00342343", "sbUid": "efgh_56785454333" }, { "uid": 10, "userName": "venkat00342", "sbUid": "efgh_56785454" } ] }, { "name": "Course Mentor", "members": [ { "uid": 9, "userName": "venkat002", "sbUid": "efgh_5678" }, { "uid": 8, "userName": "venkat001", "sbUid": "abcd_1234" }, { "uid": 12, "userName": "Mentor", "sbUid": null }, { "uid": 1, "userName": "admin", "sbUid": null } ] } ] } }
2. Add multiple users into multiple groups
End Point
{{host}}/api/forum/v3/group/membership
Request Body
{ "request": { "groups": [ "Course owner" // nodebb group name ], "members": [ { "sbUid": "8454cb21-3ce9-4e30-85b5-fade097880d8", // sunbird user identifier "sbUserName": "ntptest104" // sunbird username } ] } }
Response
This api will return list of users added into that group along with newly added user.
{ "id": ".api.forum.v3.group.membership", "ver": "1.0", "ets": 1615211148516, "params": { "resmsgid": "9f62cf7a-ec3c-4939-a0f7-aa71a0f1b233", "msgid": "", "status": "Success" }, "responseCode": "OK", "result": { "groups": [ { "name": "Course owner", "members": [ { "uid": 2, "userName": "venkat", "sbUid": null }, { "uid": 18, "userName": "ntptest104", "sbUid": "8454cb21-3ce9-4e30-85b5-fade097880d8" }, { "uid": 17, "userName": "test-venkat-22", "sbUid": "abcd_12342222211q2332322222" }, { "uid": 16, "userName": "test-venkat-2", "sbUid": "abcd_12342222211q233232" }, { "uid": 15, "userName": "test-venkat-1", "sbUid": "abcd_12342222211q2" }, { "uid": 1, "userName": "admin", "sbUid": null } ] } ] } }
3. To check list of privileges added to a particular group with a category.
End Point
{{host}}/api/forum/v3/category/:cid/privileges
Request
{ "request": { "groups": [ "Owner Group", "registered-users" ] } }
Response Body
{ "id": ".api.forum.v3.category.268.privileges", "ver": "1.0", "ets": 1615211430805, "params": { "resmsgid": "51c04946-2213-4c6f-b258-1f00425170e0", "msgid": "", "status": "Success" }, "responseCode": "OK", "result": { "groups": [ { "name": "Owner Group", "nameEscaped": "Owner Group", "privileges": { "groups:find": false, "groups:read": false, "groups:topics:read": false, "groups:topics:create": true, "groups:topics:reply": true, "groups:topics:tag": false, "groups:posts:edit": false, "groups:posts:history": false, "groups:posts:delete": false, "groups:posts:upvote": false, "groups:posts:downvote": false, "groups:topics:delete": false, "groups:posts:view_deleted": false, "groups:purge": false, "groups:moderate": true }, "isPrivate": true, "isSystem": false }, { "name": "registered-users", "nameEscaped": "registered-users", "privileges": { "groups:find": true, "groups:read": true, "groups:topics:read": true, "groups:topics:create": false, "groups:topics:reply": false, "groups:topics:tag": true, "groups:posts:edit": true, "groups:posts:history": true, "groups:posts:delete": true, "groups:posts:upvote": true, "groups:posts:downvote": true, "groups:topics:delete": true, "groups:posts:view_deleted": false, "groups:purge": false, "groups:moderate": false }, "isPrivate": true, "isSystem": true } ] } }