cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
Introduction
 A sample code to demonstrate adding shares using the Sisense API in .NET.
The programs flow is a follows:
  1. Retrieve the authentication token using:
  2. Retrieve userID using:
  3. Retrieve the current shares for the dashboard using:
  4. Share the dashboard with the user by updating the shares of the dashboard using:
Pre-Req.
This code uses the RestSharp and the Newtonsoft.Jason.linq packages both available through NuGet.
If you are using Microsoft Visual Studio, see here for instructions on how to install the NuGet extension and here for instructions on how to add packages to your solution.
Once installed, use the NuGet package manager to install the RestSharp and Newtonsoft.Jason.linq packages.
Running the Program
To run the program, modify the code as follows:
  1. In the main method, replace the following:
  • <User Email> with a user's email
  • <Dashboard ID> with your dashboard's ID
static void Main(string[] args)
{
   string token = getToken();
   Console.WriteLine(token);

   string userID = getUserID("<User Email>", token);
   Console.WriteLine(userID);

   JArray curr_shares = getDashboardShares("<Dashboard ID>", token);
   Console.WriteLine(curr_shares.ToString());

   addShares("<Dashboard ID>", curr_shares, userID, "user", "view", false, token);
}
  • In the getToken() method, replace the following:
  • <Admin User Email> with the admin's userID
  • <Admin User Password> with the admin's password
  • <Host:Port> with you host and port
static string getToken()
 {
    var client = new RestClient("http://<Host:Port>/api/v1/authentication/login");
    var request = new RestRequest(Method.POST);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("accept", "application/json");
    request.AddHeader("content-type", "application/x-www-form-urlencoded");

    request.AddParameter("username", "<Admin User Email>");
    request.AddParameter("password", "<Admin User Password>");

    IRestResponse response = client.Execute(request);

    JObject obj = JObject.Parse(response.Content);

    return obj.GetValue("access_token").ToString();

}
The Script
C# code attached below.
Rate this article:
Version history
Last update:
‎02-16-2024 10:19 AM
Updated by: