Page History
An access token needs to be obtained to use Yellowfin’s REST services.
A token can be generated with the POST /api/refresh-tokens end-point.
This service initializes a security token, and the access token is also returned in the request response. The access token needs to be provided in the header for all the other REST services mentioned in this document.
Token Generation Code
The following examples illustrate how to fetch an access token in various programming languages.
This Java Code example uses Apache HTTP Client and GSON for handling REST calls and JSON serialization. This also includes code for fetching an access token.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
package rest.code.examples;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
* Request an access token from the Yellowfin refresh-tokens REST end-point
*/
public class GetLoginToken {
public static void main(String[] args) throws Exception {
String host = "http://localhost:8080/yellowfinHead";
String restUsername = "admin@yellowfin.com.au";
String restPassword = "test";
Content c = Request.post(host + "/api/refresh-tokens")
.addHeader("Authorization", "YELLOWFIN ts=" + System.currentTimeMillis() + " , nonce=" + new Random().nextLong())
.addHeader("Accept", "application/vnd.yellowfin.api-v1+json")
.addHeader("Content-Type", "application/json")
.bodyString("{ \"userName\": \""+ restUsername + "\",\"password\": \""+ restPassword + "\"}", null)
.execute().returnContent();
JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
JsonElement accessToken = jsonObject.getAsJsonObject("_embedded").getAsJsonObject("accessToken").get("securityToken");
if (accessToken!=null) {
System.out.println("Access Token: " + accessToken);
} else {
System.out.println("Token not retrieved");
}
}
} |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
namespace YellowfinAPIExamples;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
class GetLoginToken
{
static async Task Main(string[] args)
{
string host = "http://localhost:8080/yellowfinHead";
string restUsername = "admin@yellowfin.com.au";
string restPassword = "test";
using (var client = new HttpClient())
{
// Generate nonce
long nonce = new Random().NextInt64();
// Create HTTP request
var request = new HttpRequestMessage(HttpMethod.Post, host + "/api/refresh-tokens");
request.Headers.Add("Authorization", "YELLOWFIN ts=" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + ", nonce=" + nonce);
request.Headers.Add("Accept", "application/vnd.yellowfin.api-v1+json");
request.Content = new StringContent(
JsonConvert.SerializeObject(new { userName = restUsername, password = restPassword }),
MediaTypeHeaderValue.Parse("application/json")
);
// Send request and get response
HttpResponseMessage response = await client.SendAsync(request);
string responseContent = await response.Content.ReadAsStringAsync();
// Parse JSON response
JObject jsonObject = JsonConvert.DeserializeObject<JObject>(responseContent);
string accessToken = jsonObject["_embedded"]["accessToken"]["securityToken"].ToString();
if (!string.IsNullOrEmpty(accessToken))
{
Console.WriteLine("Access Token: " + accessToken);
}
else
{
Console.WriteLine("Token not retrieved");
}
}
}
} |
Code Block | ||||
---|---|---|---|---|
| ||||
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"time"
)
func main() {
host := "http://localhost:8080/yellowfinHead"
restUsername := "admin@yellowfin.com.au"
restPassword := "test"
// Generate nonce
nonce := rand.Int63()
// Create request body
requestBody, err := json.Marshal(map[string]string{
"userName": restUsername,
"password": restPassword,
})
if err != nil {
fmt.Println("Error marshaling request body:", err)
return
}
// Create HTTP client
client := &http.Client{}
// Create HTTP request
request, err := http.NewRequest("POST", host+"/api/refresh-tokens", bytes.NewBuffer(requestBody))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Add request headers
request.Header.Set("Authorization", fmt.Sprintf("YELLOWFIN ts=%d, nonce=%d", time.Now().UnixMilli(), nonce))
request.Header.Set("Accept", "application/vnd.yellowfin.api-v1+json")
request.Header.Set("Content-Type", "application/json")
// Send HTTP request
response, err := client.Do(request)
if err != nil {
fmt.Println("Error sending request:", err)
return
}
defer response.Body.Close()
// Read response body
responseBody, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
// Parse JSON response
var jsonResponse map[string]interface{}
err = json.Unmarshal(responseBody, &jsonResponse)
if err != nil {
fmt.Println("Error parsing JSON response:", err)
return
}
// Get access token from response
accessToken, ok := jsonResponse["_embedded"].(map[string]interface{})["accessToken"].(map[string]interface{})["securityToken"].(string)
if !ok {
fmt.Println("Token not retrieved")
return
}
fmt.Println("Access Token:", accessToken)
} |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
const fetch = require('node-fetch');
async function main() {
const host = "http://localhost:8080/yellowfinHead";
const restUsername = "admin@yellowfin.com.au";
const restPassword = "test";
// Generate nonce
const nonce = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
// Create request headers
const headers = {
'Authorization': `YELLOWFIN ts=${Date.now()}, nonce=${nonce}`,
'Accept': 'application/vnd.yellowfin.api-v1+json',
'Content-Type': 'application/json'
};
// Create request body
const body = JSON.stringify({
userName: restUsername,
password: restPassword
});
try {
// Make POST request
const response = await fetch(`${host}/api/refresh-tokens`, {
method: 'POST',
headers: headers,
body: body
});
// Check if request was successful
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// Parse JSON response
const jsonResponse = await response.json();
const accessToken = jsonResponse._embedded.accessToken.securityToken;
if (accessToken) {
console.log(`Access Token: ${accessToken}`);
} else {
console.log("Token not retrieved");
}
} catch (error) {
console.error("Error:", error.message);
}
}
main(); |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php
function main()
{
$host = "http://localhost:8080/Yellowfin";
$restUsername = "admin@yellowfin.com.au";
$restPassword = "test";
// Generate nonce
$nonce = mt_rand();
// Create request body
$requestBody = json_encode(array(
"userName" => $restUsername,
"password" => $restPassword
));
// Create request headers
$headers = array(
'Authorization: YELLOWFIN ts=' . intval(microtime(true) * 1000) . ', nonce=' . $nonce,
'Accept: application/vnd.yellowfin.api-v1+json',
'Content-Type: application/json'
);
$response = httpRequest('POST', "$host/api/refresh-tokens", $headers, $requestBody);
// Parse JSON response
$jsonResponse = json_decode($response, true);
// Get access token from response
if (isset($jsonResponse["_embedded"]["accessToken"]["securityToken"])) {
$accessToken = $jsonResponse["_embedded"]["accessToken"]["securityToken"];
echo "Access Token: " . $accessToken;
} else {
echo "Token not retrieved";
}
}
function httpRequest($method, $url, $headers, $data = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if ($data !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Error: ' . curl_error($ch));
}
curl_close($ch);
return $response;
}
main()
?> |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import json
import random
import time
import requests
host = "http://localhost:8080/yellowfinHead"
rest_username = "admin@yellowfin.com.au"
rest_password = "test"
# Generate nonce
nonce = random.randint(0, 2**63 - 1)
# Create request body
request_body = json.dumps({
"userName": rest_username,
"password": rest_password
})
# Create request headers
headers = {
'Authorization': f'YELLOWFIN ts={int(time.time() * 1000)}, nonce={nonce}',
'Accept': 'application/vnd.yellowfin.api-v1+json',
'Content-Type': 'application/json'
}
# Send HTTP request
response = requests.post(host + "/api/refresh-tokens", headers=headers, data=request_body)
# Check response status
if response.status_code == 200:
# Parse JSON response
json_response = response.json()
access_token = json_response["_embedded"]["accessToken"]["securityToken"]
print("Access Token:", access_token)
else:
print("Token not retrieved") |
...
Table of Contents | ||
---|---|---|
|
Before beginning the “Getting Started” sections, you must have the following:
- A Yellowfin instance installed including the Ski Team Tutorial content
- A Yellowfin login with the “Administrator” role
Roles, Users, Groups, Folders & Sub Folders
Learning Outcomes
After completing this section, you will be able to:
- Adjust user roles and permissions
- Add new users to your Yellowfin server
- Create content folders and sub folders
Roles
Every user is allocated to a single role that specifies which functions they can access. A user cannot be allocated to multiple roles simultaneously, however you are able to switch the role a user is allocated to. Yellowfin ships with a number of pre-configured roles, and administrators can create custom roles.
Additional Learning: See more information on roles and the built-in role types.
Navigate to the Roles section in the Admin Console and compare Report Builder permissions between the “Consumer and Collaborator” role to the “System Administrator” role.
- Click on the Burger Bun . Expand the Administration section and click on Admin Console.
- Open the Roles section. A list of default role options is displayed.
- Click on “Consumer & Collaborator” to show the detailed configuration of that role.
Here you can see the description of the role as well as which functions have been enabled for this role. Notice that the Default Role option is toggled on. This means that for every new user added to Yellowfin, unless specified otherwise, their role will be set to the “Consumer & Collaborator” role. - Scroll down to the Report Builder section, click on it to expand it and show the detail.
Notice that the “Consumer and Collaborator” role has no permissions enabled in the Report Builder. This means users with this role cannot create reports. - Close the window to return to the Roles section in the Administration Console.
- Click on “System Administrator”.
- Expand the Report Builder section.
Notice how many more permissions are enabled in the Report Builder compared with the “Consumer and Collaborator” role. - Close the window to return to the Administration Console.
Note: For the purposes of this demonstration, we will be using the existing roles. However, as an administrator you have the option to build a role from scratch, picking exactly which functions this role will have.
Additional Learning: See more information on building roles.
Note: To continue on in the “Getting Started with Yellowfin” section, you must have the “System Administrator” role or permission to edit Views, Reports, and Dashboards.
Users
To access the Yellowfin system, one must have a user login. Administrators can add, edit, and delete users, as well as assign roles to users.
Creating a User
- Open the Users section. Here you have the option to add new users and modify existing users.
To add a user, follow the steps below with information specific to your new user.
- Select Add to create a user.
- Enter the name and email of the new user.
- Select a role from the built-in options.
Note: Choose their role depending on what permissions they should be able to access. See more information on the built-in role types.
- Enter a password for your new user. Select Create User.
Note: Once this user logs in for the first time using the password you’ve created for them, they are prompted to change their password.
Note: As a System Administrator, it is possible to change a given user’s role at any time.
You will now see your new user appear under the list of people in the Users section.
Note: To edit their profile, select the drop down on their title. From there, you have the option to edit the user, change their role, or delete the user.
Additional Learning: You can import multiple users at a time. See more information on bulk user import. Users can also be onboarded using the Web Services API, SAML or LDAP integration.
User Groups
Users can be grouped together and treated as a single entity in multiple parts of the application, such as security and broadcasting processes.
Administrators can create and manage groups through the Admin Console.
Additional Learning: See more information on user groups.
Content Folders
All content (Views, Reports, Dashboards, Stories, Presentations, and Data Transformation Flows) must be stored in a sub folder. All sub folders are contained in a folder. Folders allow you to group sub folders, but do not store any content directly. Security of content can be managed at the sub folder level, but not at the parent folder level.
Additional Learning: See more information on content folders.
Create a Content Folder and Sub Folder
...
Styleclass | ||
---|---|---|
| ||
top |