Like what you see? Have a play with our trial version.

Error rendering macro 'rw-search'

null

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

To use Yellowfin’s REST services, an access token needs to be obtained.
A token can be generated with the
POST /api/refresh-tokens end-pointThis 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.

Java

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.

Java
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");
        }

    }
}



  • No labels