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

Error rendering macro 'rw-search'

null

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;

import java.io.IOException;
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;
/**
 * Create a user using the Yellowfin REST API
 */
public class CreateAUser {
    public static void main(String[] args) throws Exception {

        String host = "http://localhost:8080/Yellowfin";
        String restUsername = "admin@yellowfin.com.au";
        String restPassword = "test";

        String createUserPayload = "[ {" +
                "  \"userId\": \"user1\"," +
                "  \"emailAddress\": \"user1@yellowfin.com.au\"," +
                "  \"roleCode\": \"Consumer & Collaborator\"," +
                "  \"password\": \"test\"," +
                "  \"firstName\": \"User\"," +
                "  \"lastName\": \"One\"," +
                "  \"languageCode\": \"EN\"," +
                "  \"timeZoneCode\": \"AUSTRALIA/SYDNEY\"" +
                " } ]";




        String token = generateToken(host, restUsername, restPassword);
        System.out.println("Payload: " + createUserPayload);
        Content c = Request.post(host + "/api/admin/users")
Code Block
languagec#
titleC#
collapsetrue
namespace YellowfinAPIExamples;

using System.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

public class CreateAUser
{
    static async Task Main(string[] args)
    {
        string host = "http://localhost:8080/Yellowfin";
        string restUsername = "admin@yellowfin.com.au";
        string restPassword = "test";
            
        string createUserPayload = "[ {" +
                                   "  \"userId\": \"user1\"," +
                                   "  \"emailAddress\": \"user1@yellowfin.com.au\"," +
                                   "  \"roleCode\": \"Consumer & Collaborator\"," +
                                   "  \"password\": \"test\"," +
                                   "  \"firstName\": \"User\"," +
                                   "  \"lastName\": \"One\"," +
                                   "  \"languageCode\": \"EN\"," +
                                   "  \"timeZoneCode\": \"AUSTRALIA/SYDNEY\"" +
                                   " } ]";

        string token = await GenerateToken(host, restUsername, restPassword);

        Console.WriteLine("Payload: " + createUserPayload);

        using (HttpClient client = new HttpClient())
        {
            long nonce = new Random().NextInt64();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, host + "/api/admi
Code Block
titleGo
collapsetrue
package main

import (
        "bytes"
        "encoding/json"
        "fmt"
        "io/ioutil"
        "math/rand"
        "net/http"
        "time"
)

func main() {
        host := "http://localhost:8080/Yellowfin"
        restUsername := "admin@yellowfin.com.au"
        restPassword := "test"

        createUserPayload := `[{
                "userId": "user1",
                "emailAddress": "user1@yellowfin.com.au",
                "roleCode": "Consumer & Collaborator",
                "password": "test",
                "firstName": "User",
                "lastName": "One",
                "languageCode": "EN",
                "timeZoneCode": "AUSTRALIA/SYDNEY"
        }]`

        token, err := generateToken(host, restUsername, restPassword)
        if err != nil {
                fmt.Println("Error generating token:", err)
                return
        }

        fmt.Println("Payload:", createUserPayload)

        client := &http.Client{}
        request, err := http.NewRequest("POST", host+"/api/admin/users", bytes.NewBuffer([]byte(createUserPayload)))
        if err != nil {
Code Block
languagejs
titleJavaScript
collapsetrue
const fetch = require("node-fetch");

async function main() {
    const host = "http://localhost:8080/Yellowfin";
    const restUsername = "admin@yellowfin.com.au";
    const restPassword = "test";

    const createUserPayload = JSON.stringify([{
        userId: "user1",
        emailAddress: "user1@yellowfin.com.au",
        roleCode: "Consumer & Collaborator",
        password: "test",
        firstName: "User",
        lastName: "One",
        languageCode: "EN",
        timeZoneCode: "AUSTRALIA/SYDNEY"
    }]);

    const token = await generateToken(host, restUsername, restPassword);

    if (token === null) {
        console.error("Failed to retrieve access token");
        return;
    }

    console.log("Payload:", createUserPayload);

    const nonce = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);

    const headers = {
        'Authorization': `YELLOWFIN ts=${Date.now()}, nonce=${nonce}, token=${token}`,
        'Accept': 'application/vnd.yellowfin.api-v1+json',
        'Content-Type': 'application/json'
    };

    try {
        const response = await fetch(`${host}/api/admin/users`, {
Code Block
languagephp
titlePHP
collapsetrue
<?php
function main() {
    $host = "http://localhost:8080/Yellowfin";
    $restUsername = "admin@yellowfin.com.au";
    $restPassword = "test";

    $createUserPayload = json_encode(array(
        array(
            "userId" => "user1",
            "emailAddress" => "user1@yellowfin.com.au",
            "roleCode" => "Consumer & Collaborator",
            "password" => "test",
            "firstName" => "User",
            "lastName" => "One",
            "languageCode" => "EN",
            "timeZoneCode" => "AUSTRALIA/SYDNEY"
        )
    ));

    try {
        $token = generateToken($host, $restUsername, $restPassword);
    } catch (Exception $e) {
        echo "Error generating token: " . $e->getMessage();
        return;
    }

    echo "Payload: " . $createUserPayload . "\n";

    $nonce = mt_rand();
    $headers = array(
        'Authorization: YELLOWFIN ts=' . intval(microtime(true) * 1000) . ', nonce=' . $nonce . ', token=' . $token,
        'Accept: application/vnd.yellowfin.api-v1+json',
        'Content-Type: application/json'
    );

    try {
        $response = httpRequest('POST', "$host/api/admin/users", $headers, $createUserPayload);
        echo $response;
    } catch (Exception $e) {
Code Block
languagepy
titlePython
collapsetrue
import json
import random
import time

import requests

def main():
    host = "http://localhost:8080/Yellowfin"
    rest_username = "admin@yellowfin.com.au"
    rest_password = "test"

    create_user_payload = json.dumps([{
        "userId": "user1",
        "emailAddress": "user1@yellowfin.com.au",
        "roleCode": "Consumer & Collaborator",
        "password": "test",
        "firstName": "User",
        "lastName": "One",
        "languageCode": "EN",
        "timeZoneCode": "AUSTRALIA/SYDNEY"
    }])

    try:
        token = generate_token(host, rest_username, rest_password)
    except Exception as e:
        print(f"Error generating token: {e}")
        return

    print("Payload:", create_user_payload)

    nonce = random.randint(0, 2 ** 63 - 1)

    headers = {
        'Authorization': f'YELLOWFIN ts={int(time.time() * 1000)}, nonce={nonce}, token={token}',
        'Accept': 'application/vnd.yellowfin.api-v1+json',
        'Content-Type': 'application/json'
    }

    try:

...