Page History
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
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 | ||||
---|---|---|---|---|
| ||||
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
<?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 | ||||||
---|---|---|---|---|---|---|
| ||||||
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: |
...