Add users to a 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 } & element apass { text }) & element lifetime { iso8601-period }? & element expires { timestamp }? & element primary { boolean }? & element singleuse { boolean }? & element responsibilities { element name { text }* }? }
Field names and descriptions
ACL - User role. Determines the token access and permissions. The list of user roles can be found here
descr - Short textual description of the user (e.g., name of device)
apass - Password string
lifetime - Lifetime of the user; infinite if not provided
expires - Date when the user will expire
primary - "true" if a primary-type user is required
singleuse - "true" if the user expires after a single use
responsibilities - 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.