You are browsing documentation for an outdated version. See the latest documentation here.

Admins Examples

How to Invite and Register an Admin

Introduction

Can be used for automation

Prerequisites

  1. export USERNAME=<username>
  2. export EMAIL=<email>
  3. export WORKSPACE=<workspace>
  4. export HOST=<admin_api_host>
  5. export TOKEN=Kong-Admin-Token:<super_admin_token>

for example:

  1. export USERNAME=drogon
  2. export EMAIL=test@test.com
  3. export WORKSPACE=default
  4. export HOST=127.0.0.1:8001
  5. export ADMIN_TOKEN=Kong-Admin-Token:hunter2

May benefit from HTTPie and jq.

Step 1

Extract and store the token from the registration URL, either by manually creating an environment variable or by echoing and piping with jq:

Manual method example:

  1. Send a request to the registration URL

    1. http $HOST/$WORKSPACE/admins/$USERNAME?generate_register_url=true $TOKEN
  2. Copy the response and export as an environment variable, for example:

    1. export REGISTER_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDUwNjc0NjUsImlkIjoiM2IyNzY3MzEtNjIxZC00ZjA3LTk3YTQtZjU1NTg0NmJkZjJjIn0.gujRDi2pX_E7u2zuhYBWD4MoPFKe3axMAq-AUcORg2g

Programmatic method (requires jq):

  1. REGISTER_TOKEN=$(http $HOST/$WORKSPACE/admins/$USERNAME?generate_register_url=true $TOKEN | jq .token -r)

Step 2

  1. http $HOST/$WORKSPACE/admins/register token=$REGISTER_TOKEN username=$USERNAME email=$EMAIL password="<new_password>"