Users¶
Resolve the identity behind a credential or look up a user by numeric ID.
Setup¶
These snippets share this client. Replace the URL and token with your DataHub details. The complete sample files use offline responses when run by the documentation checks.
#r "nuget: DataHubClient"
open DataHubClient
let client =
DataHubClient("https://hub.example", Authentication.PersonalAccessToken("your-datahub-pat"))
import { DataHubClient } from "@nfdi4plants/datahub-client";
import { Authentication } from "@nfdi4plants/datahub-client/Http/Authentication.js";
const client = new DataHubClient(
"https://hub.example", Authentication.PersonalAccessToken("your-datahub-pat"));
import asyncio
from datahub_client import DataHubClient, Authentication
client = DataHubClient(
"https://hub.example", Authentication.PersonalAccessToken("your-datahub-pat"))
GetCurrentAsync¶
Get the user authenticated by the configured token. Email is optional and is populated only by this endpoint.
let currentUser =
client.Users.GetCurrentAsync() |> Async.RunSynchronously
printfn "%s (%A)" currentUser.Username currentUser.Email
const currentUser = await client.Users.GetCurrentAsync();
console.log(currentUser.Username, currentUser.Email ?? "No email");
async def get_current_example():
current_user = await client.Users.GetCurrentAsync()
print(current_user.Username, current_user.Email or "No email")
asyncio.run(get_current_example())
GetAsync¶
Get a user by their instance-wide numeric ID.
let user =
client.Users.GetAsync(7) |> Async.RunSynchronously
printfn "%s: %s" user.Username user.WebUrl
const user = await client.Users.GetAsync(7);
console.log(user.Username, user.WebUrl);
async def get_example():
user = await client.Users.GetAsync(7)
print(user.Username, user.WebUrl)
asyncio.run(get_example())