Forums

Best practices for programmatically adding users to roles?

This question is answered

What is the best method of programmatically adding users to specific roles within Telligent Community? I noticed that the REST API does not appear to support user role updates, only retrieval. Is the only option to call database stored procedures directly or are there better options?

For what it's worth, I am writing two small applications to manage user accounts within our system:

  • a console application that manages a subset of user accounts based on Active Directory membership information (accounts for staff and students).
  • a web-based application that manages the remaining user accounts based on periodic, user-uploaded CSV files from our CRM-like system (contains parent contact information)

With each application, I will be creating/updating/deleting user accounts and need the ability to place users into school-based roles.

Verified Answer
  • Whilst there are no endpoints for editing user roles through the v2 apis, there are endpoints in the v1 api - see telligent.com/.../membership.aspx for more details.

  • Robert, the v1 REST APIs are not deprecated yet. There is a lot of functionality still that exists in v1 that has not been built in the v2 API. If you have a choice of one vs the other for the same task then definitely choose v2, but you're still safe in using the v1 API.

All Replies
  • Whilst there are no endpoints for editing user roles through the v2 apis, there are endpoints in the v1 api - see telligent.com/.../membership.aspx for more details.

  • Hi Robert,

    We have done this using the RoleService() with the internal API. Something like:

    CommunityServer.Components.RoleService roleService = Telligent.Common.Services.Get<CommunityServer.Components.RoleService>();

    //need to get/create csUser object above here

    roleService.AddUserToRole(csUser);

    This worked really well for us, I'd imagine the recomended approach is to use the webservice though.

    Thanks

    Adam

  • Thanks, Alex! I take it the v1 REST APIs have not been deprecated in favor of the v2 REST APIs? I was concerned that the v1 APIs would be removed and did not give them much notice.

  • Robert, the v1 REST APIs are not deprecated yet. There is a lot of functionality still that exists in v1 that has not been built in the v2 API. If you have a choice of one vs the other for the same task then definitely choose v2, but you're still safe in using the v1 API.

  • Thanks, Dan!

  • Adam, when you did the RoleService thing was that from a Console app?

    I've tried this article telligent.com/.../1041954.aspx

    But I have a problem getting the CSMemberRoleProfileProvider loaded, getting this error: The type initializer for 'CommunityServer.Components.MemberRoleProfileProvider' threw an exception." ("System.TypeInitializationException")

    Also just tried your example and getting this error: "The service locator has not been initialized" ("System.InvalidOperationException")

    Anyone have any idea what I do wrong?

  • We do not support running the core Telligent Evolution platform binaries outside of a Telligent Evolution website - mainly because they rely on HTTPContext and thus don't work.

    To interact with the Telligent Evolution platform from a console app, the recommended and supported route is to use the WebServices APIs.