Sample Code for Sharing Dashboards Using the REST API in .NET
Introduction
A sample code to demonstrate adding shares using the Sisense API in .NET.
The programs flow is a follows:
- Retrieve the authentication token using:
- Retrieve userID using:
- Retrieve the current shares for the dashboard using:
- Share the dashboard with the user by updating the shares of the dashboard using:
Pre-Req.
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:
- 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.
Updated 02-16-2024
intapiuser
Admin
Joined December 15, 2022