Public
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Frequent Advisor

Assigning the badge to a large specific CSV list of community users

Hi,

 

Got a specific CSV list of almost 1,500 community users which I need to reward with a badge. There is no connection or community-related logic behind the list members. How to automate the assigning the badge for them?

 

Thank you!

 

12 Replies 12
Highlighted
Honored Contributor

@Myko_P - 

As there is no direct call to add a badge to users. 

 

There is only one way I can think of, you need to create a role for each badge.  e,g you CSV file

id, badge name1

id2,badge name 2

 

One way you can add a new column with role name

id, badge name1, badge_name1  or you can have the same role name as the badge. 

 

You need some customization to assign a role from CSV file.  Below is the API call you can use to assign a role 

http://community.lithium.com/community-name/restapi/vc/roles/id/[id] /users/add

https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv1&leaf-id=...

 

From the badge rule, you can choose Roles and map to according to the badge. 

 

Screenshot_27.png

 

When a role is assigned to the users, a new badge will be assigned as well. Let me know if this helps.

 

 

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted

Thank you, @TariqGrazitti ,

I got only community's usernames (user logins) in my CSV list with no user-ids. And I have to assign the same badge to each user from the list. I created a role "Online-Gamer" and the badge named "Online-Gamer" for that.
My CSV list has 2 columns now: user_login,badge_name

So how should my API call look like to assign the same role for the different user names (user logins)?

 

Highlighted

@Myko_P-

 

You can pass login/username in the API as well. e.g

 

jQuery.post("/restapi/vc/roles/id/<roleID>/users/add?role.user=login/<username>");

 

 

As in the CSV file, you have roles name not the roles id. You will need to make another call to get the role id which can be passed in add role call.

 

/restapi/vc/roles/name/<roleName>

 

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted

Thank you so much on that @TariqGrazitti !

 

It is still not clear to me, what kind of customization I need to assign a role from CSV file? 

Highlighted

@Myko_P- Example below is your CSV file.

 

username, role

 

Myko_p, gamer
TariqGrazitti, gamer
testuser, gamer
testuser2, gamer2

 

 

<#assign csv = "Myko_p, gamer
tariq, gamer
testuser, gamer
testuser2, gamer2" />

<#assign csv = csv?split("\n") />

<#list csv as row>
   <#assign column = row?split(",") />
   <#assign userName = column[0] />
   <#assign roleName = column[1] />
   <#assign roleID = restadmin("/roles/name/${roleName?trim}").role.id />
   <#assign roleID = restadmin("/roles/id/${roleID}/users/add?role.user=login/${userName?trim}") />
</#list>

 

Note: in the above example I have stored CSV content directly on the component as a variable. You can also create something where you can upload CSV file and send the CSV data to an endpoint.

 

Below is the example how to read csv file http://jsfiddle.net/W8fME/266/

 

Give kudos if you find my posts helpful or mark solution if it answers your query.
Tariq
Highlighted
Khoros Alumni (Retired)

There is actually no need at all for any coding. If you have a CSV file in the format username,role simply feed that to the role importer: https://community.lithium.com/t5/Roles-and-permissions/Import-user-roles-from-a-CSV-file/ta-p/24276

Khoros Best Practice until August 2019. Onwards posting as Claudius.
Learn how to master Khoros. Learn Best Practice in the Community Documentation
If you appreciate my efforts, please give me a kudo ↓
Accept as solution to help others find it faster.
Highlighted

Thanks for the advise @ClaudiusH ,

 

I tried to import roles from my CSV using the way you mentioned.

But It looks like nothing happens. New Role didn’t appear in the Community Admin > Users > Permissions > Roles interface. I didn’t receive any error messages and email notifications despite the fact I checked “Send confirmation email” option. 

 

Highlighted
Honored Contributor

@Myko_P

 

Forgive me if I've made an incorrect assumption, but it sounds as though you have missed the step of creating the new role. 

 

The CSV input process is just for assigning users to an existing role. It will ignore roles that do not already exist.

 

Hope that helps,

 

Jason

Generic1.jpg

Highlighted


@JasonHill wrote:

@Myko_P

 

Forgive me if I've made an incorrect assumption, but it sounds as though you have missed the step of creating the new role. 

The CSV input process is just for assigning users to an existing role. It will ignore roles that do not already exist.


Thank you @JasonHill, you were right. 

But it didn't help. I created needed role first and repeated role import procedure with my CSV, but nothing happened again.  When I click "List Users" button in Community Admin > Users > Permission > Roles interface I see that role's user list is empty.

I am starting to think that the Import Roles  feature is just broken  Smiley Frustrated