The Admin API
The Admin API allows you to make privileged API requests.
Create key
- Go to the Admin console and click API keys via the Developers dropdown or Tenant settings
- Click the New API key button
- Set the Description field to
Getting Started
- Select
Admin API
from Type dropdown - Select
Read and write
from the Everything scope dropdown - Click the Create button
- Click Copy when the newly created key appears
Install SDK
# No setup required
npm install @userhub/sdk
go get -u github.com/userhubdev/go-sdk
composer require userhub/sdk
pip install -U userhub-sdk
Make a request
curl https://api.userhub.com/admin/v1/users \
-H "Authorization: Bearer $USERHUB_ADMIN_KEY"
import { AdminApi } from "@userhub/sdk";
const adminApi = new AdminApi(process.env.USERHUB_ADMIN_KEY);
const res = await adminApi.users.list();
for (const user of res.users) {
console.log(user.id);
}
package main
import (
"context"
"fmt"
"os"
"github.com/userhubdev/go-sdk/adminapi"
)
func main() {
ctx := context.Background()
adminApi, err := adminapi.New(os.Getenv("USERHUB_ADMIN_KEY"))
if err != nil {
panic(err)
}
res, err := adminApi.Users().List(ctx, nil)
if err != nil {
panic(err)
}
for _, user := range res.Users {
fmt.Println(user.Id)
}
}
<?php
require __DIR__.'/vendor/autoload.php';
use UserHub\AdminApi;
$adminApi = new AdminApi(getenv('USERHUB_ADMIN_KEY'));
$res = $adminApi->users->list();
foreach ($res->users as $user) {
echo $user->id.PHP_EOL;
}
import os
from userhub_sdk import AdminApi
admin_api = AdminApi(os.environ.get("USERHUB_ADMIN_KEY"))
res = admin_api.users.list()
for user in res.users:
print(user.id)
Note: When making requests on behalf of a user it is almost always preferable to use the User API instead.