How to get user roles

Hello,

I have try to get logged in Users role with the help of this page detail : http://telligent.com/community/developers/w/developer6/20564.aspx.

But when execute this below lines with my userid-

var requestUrl = "XYZ.com/api.ashx/v2/roles/permissions/user/{userid}.xml (or .json)

var xml = webClient.DownloadString(requestUrl);

it throws error- "Unable to connect to the remote server"

can anyone please help me to sort it out.

Thanks

Parimal Patel

  • Did you update the requestUrl with the URL of your actual site?

  • In reply to Luke D:

    yes i have update it.....

  • In reply to Parimal:

    Hi Luke D,

         could you please tell me what issue exactly occur....

  • In reply to Parimal:

    Hi
    Any buddy have a solution regarding my issue to get roles of user.

    Thanks & Regard's
    Parimal.
  • In reply to Parimal:

    Can you post your actual code? The sample in your original post isn't valid code.
  • In reply to Ben Tiedt:

    Have you set the authentication credentials for the rest api? You won't be able to access the api if you haven't created an api key and are passing this in the header of the request. You could use the widget api to do this also depending on what version of Telligent/Zimbra you are on. As Ben said it would be useful if you posted more of your code and have more details on your version number and where you are trying to run the code.
  • In reply to Ben Tiedt:

    Hi, Ben Tiedt

             Thanks for Reply... 

    My code i have mention below. Please let me know where i need to change.

     

    //Help Link: http://community.zimbra.com/developers/w/developer6/20564
    //Get API and name through this way- Link:http://community.zimbra.com/developers/w/wiki/how-to-generate-an-api-key

    var adminKey = String.Format("{0}:{1}", "MyAPI KEy", "MyName");
    var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));
    webClient.Headers.Add("Rest-User-Token", adminKeyBase64);
    userid = CSContext.Current.User.Profile.User.UserID;
    var requestUrl = String.Format("https://MySiteUrlHere.com/api.ashx/v2/roles/user/{0}.xml", userid); // or .json
    var xml = webClient.DownloadString(requestUrl);
    System.Data.DataSet ds = new System.Data.DataSet();
    using (StringReader stringReader = new StringReader(xml))
    {
                     ds = new System.Data.DataSet();
                     ds.ReadXml(stringReader);
    }

    Thanks & regards 

    Parimal

  • In reply to Adam Seabridge:

    Hi Adam Seabridge,

    Thanks for reply,

    I have using tellingent version 7.0. and i have create widget using c# file.
    and i have post my code in my last comment please check.
  • In reply to Parimal:

    So if this is a widget, why are you not using widget studio?
  • In reply to Luke D:

    Hi Luke Davidson,

    Actually, I have not much idea about widget studio programming. so I have created Widget using c# and create Dll then put in project.
  • In reply to Parimal:

    I would attempt to read the widget api documentation then
  • In reply to Luke D:

    Or try use the PublicApi (as opposed to REST) in your code
  • In reply to Luke D:

    I've written you an working widget example. See below.

    You really should read the documentation:

    http://community.zimbra.com/developers/w/developer7/28599.core-v2-role-widget-extension

    #set($apiListResponse = $core_v2_role.List("%{Username = 'admin'}"))

    <h2>Roles for Admin</h2>

    <ul>
    #foreach($role in $apiListResponse)
    #each
    <li>$role.Name</li>
    #end
    </ul>

  • In reply to Adam Seabridge:

    By the way go to the control panel here: /controlpanel/tools/ManageWidgets/ListWidgets.aspx

    click create new widget and add the code and save it. It should look like this when you place it on the page:

  • In reply to Parimal:

    Parimal
    var adminKey = String.Format("{0}:{1}", "MyAPI KEy", "MyName");

    Ensure that you have setup the API key on your site and you specify the username associated to this key (not the common/display name)

    Parimal
    var requestUrl = String.Format("https://MySiteUrlHere.com/api.ashx/v2/roles/user/{0}.xml", userid); // or .json

    Verify that your site is accessible via HTTPS from the server on which the widget is installed. If you're using a self-signed certificate for SSL, ensure that the server trusts this certificate.

Related