Assign Group to Category via Write API
-
ad missing Groups require · NodeBB/nodebb-plugin-write-api@8136ec9
A RESTful JSON-speaking API allowing you to write things to NodeBB - ad missing Groups require · NodeBB/nodebb-plugin-write-api@8136ec9
GitHub (github.com)
-
@yapne said in Assign Group to Category via Write API:
curl -XPUT -H "Authorization: Bearer <TOKEN>" --data "privileges=['groups:find:false']&groups=['write-group']" http://<hostname>/api/v2/categories/7/privileges
I think the correct call would use the group name instead of slug, and the privilege shouldn't have
false
at the end. Trycurl -XPUT -H "Authorization: Bearer <TOKEN>" --data "privileges=['groups:find']&groups=['Write Group']" http://<hostname>/api/v2/categories/7/privileges
ReplaceWrite Group
with the actual group name. -
@baris
I have made the following changes as suggest and it is still throwing the same error message. Tried all different combinations below and none actually worked. Any thoughts?{
"createtime": 1521473141636,
"deleted": 0,
"description": "First Write Group",
"disableJoinRequests": false,
"hidden": false,
"memberCount": 2,
"name": "Write Group",
"ownerUid": "11",
"private": true,
"slug": "write-group",
"system": false,
"userTitle": "Write Group",
"nameEncoded": "Write%20Group",
"displayName": "Write Group",
"userTitleEnabled": true,
"labelColor": "#000000",
"icon": "",
"createtimeISO": "2018-03-19T15:25:41.636Z",
"cover:url": "/assets/images/cover-default.png",
"cover:thumb:url": "/assets/images/cover-default.png",
"cover:position": "50% 50%"
} -
I am not sure, can you put a
console.log(cid, privilege, group);
before this line https://github.com/NodeBB/nodebb-plugin-write-api/blob/master/routes/v2/categories.js#L78 and try again? It sounds like the correct group name is not passed to the function. Those errors are thrown from https://github.com/NodeBB/NodeBB/blob/master/src/groups/create.js#L94-L100 -
@baris said in Assign Group to Category via Write API:
curl -XPUT -H "Authorization: Bearer <TOKEN>" --data "privileges=['groups:find']&groups=['Write Group']" http://<hostname>/api/v2/categories/7/privileges
Yeah I think the curl command is still wrong try
curl -XPUT -H "Authorization: Bearer <TOKEN>" --data "privileges[]=groups:find&groups[]='Write Group'" http://<hostname>/api/v2/categories/7/privileges
-
@baris That has resolved the issue. If i want to change the privileges for more than one action what would be the format?
I tried privileges[]=groups:find,groups:read OR privileges[]={groups:find,groups:read} OR privileges[]=[{groups:find,groups:read}]
Neither works.
Kindly please advise. Thanks
-
@yapne said in Assign Group to Category via Write API:
@baris @julianlam How do i add user(s) to the category via this write API? Are you able to advise please? Thanks
Doesn't seem the API support this. Are you able to confirm please?
-
By "adding users" do you mean giving them privileges?
Edit: if that is the case, then you may find it easier to create a group for the category, give it privileges, and then use the write API to add users to the group
-
@pitaj There is a specific reason why I am not using group. Nodebb doesn't have the capability to assign user's privileges at the topic level. Hence, we are using category as a work around for this missing feature.
Externally to NodeBB, we are giving end users the functionality to create category dynamically and assign users to it. By using group, it may end up creating a lot of groups that are going to be nightmare to maintain. Therefore, i am planning to assign the users directly to the category instead. I think the API does not support this requirement just yet. If you can advise if there is another better way to do this please? Or possibly to enhance the API to assign user's privileges to the category?
Many thanks
Nelson