Assign a badge / role to a user when he posts to a specific board
Hello,
I need to assign a badge to users that post on specific boards.
What I know is that the best way to do it is to use roles or custom fields to trigger tha attribution of a badge, because it seems there's no direct method to do it.
However, I searched for a while on the community but can't find any information about the following topics:
- How to trigger an action when a user posts a new message or create a new thread via the API ?
- How to assign a role to a user via the API ?
- How to update the value of a custom user profile field via the API ?
Which makes my work very difficult.
Does anyone know how I could implement that?
humbkr - You need to add a specific badge to the user when they post on a specific board, right? i.e. if they post in board X they get a badge named X_bdg and if they post in board Y they get a badge Y_bdg. To add to this, you'd want to add the badge even if they have posted in this board in the past, i.e. before your implementation.
Here is the anwser to your queries:
- How to trigger an action when a user posts a new message or create a new thread via the API ?
On the boards page, you can check using the API V2 if the user in context has any post in this board. Call for this would be:
SELECT * FROM messages WHERE board.id = 'BOARD_ID' AND author.id ='AUTHOR_ID'
If the size returned is > than 0, assign them the badge using next call. You can trigger this code in the page initialization tab in studio.
- How to assign a role to a user via the API ?
Ref: https://community.lithium.com/t5/Developers-Discussion/Add-User-Role-via-API/m-p/187996#M7689
- How to update the value of a custom user profile field via the API ?
/restapi/vc/users/id/[ID]/profiles/name/PROFILE_FIELD_NAME/set?value=VALUE_HERE
I hope this helps.