Add users to the subaccount
This command allows you to create users (access tokens) in the subaccount.
When a subaccount is created, one user is automatically created. However, you can generate additional users via an API call if needed.
API Request
Method POST
/users/{subaccount guid}/tokens/
Elements schema
element token { ( element acl { text } )? & element descr { text } # Short textual description of token (eg. name of device) & (element sessionkey { boolean } # States that aname and apass should be auto generated | (element aname { text }? # Optional authentication-name; GUID will be generated if not supplied & element apass { text }) # Password string & element lifetime { iso8601-period }? # lifetime of token - infinite if not supplied & element expires { timestamp }? # Date when token would be expired & element device { text }? # GUID of device this token is stored on & element primary { boolean }? # true if need to create a primary token & element singleuse { boolean }? # true if token will expire after the first usage & element responsibilities { element name { text }* # name of the responsibility. Currently supported Emergency, Technical, Financial, Invoicing, Protection }? }
Example
Method POST
https://dk-co.keepit.com/users/7h6sde-k81qxv-rjxquw/tokens
Body
<token> <acl>MasterAdmin</acl> <descr>test2@keepit.com</descr> <aname>test2@keepit.com</aname> <apass>VerySecurePassword111!!!</apass> <expires>2025-01-22T21:59:59.999Z</expires> <primary>true</primary> </token>
PowerShell script
try { # Define the API credentials and subaccount ID $username = '<API Token username>' $password = '<API Token password>' $userID = '<Subaccount GUID>' # Create the Basic Authentication header $basicauth = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${username}:${password}")) $headers = @{ "User-Agent" = "PowerShell-Keepit-API-Agent-1.0" "Authorization" = "Basic $basicauth" "Content-Type" = "application/xml" } # Construct the URL for the POST request using the user ID $url = "https://dk-co.keepit.com/users/$userId/tokens" # Define the body of the POST request $xmlBody = @" <token> <acl>MasterAdmin</acl> <descr>test2@keepit.com</descr> <aname>test2@keepit.com</aname> <apass>VerySecurePassword111!!!</apass> <expires>2025-01-22T21:59:59.999Z</expires> <primary>true</primary> </token> "@ # Send the POST request with the XML body $response = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $xmlBody -ErrorAction Stop -TimeoutSec 10 # Check the status code and display an appropriate message if ($response.StatusCode -eq 201) { Write-Host "Success" } } catch { # Handle errors and provide line number and error message $line = $_.InvocationInfo.ScriptLineNumber Write-Host "Cannot query Keepit API due to: $_" Write-Host "at line $line" }
Additional information
- The user (access token) will be created in the account that is indicated in "$userID."
- The password for the new user <apass> element should be isolated in the script in order to support special symbols. Replace the string “EnterYourPasswordHere!” with the password you wish to set.