Example
Method POST
https://dk-co.keepit.com/users/5t1sbe-s6zsgx-rtutxq/tokens/
1. With autogenerated token credentials
Body
<token>
<acl>MasterAdmin</acl>
<descr>APIcustomtoken</descr>
<sessionkey/>
<primary>false</primary>
<lifetime>P1Y</lifetime>
</token>
Additional header
Key: Accept
Value: application/vnd.keepit.v1+xml
Response
Code: 201 Created
Response body:
<credentials>
<aname>%cxZq4L+dyQsns1k6gB5Ia,a</aname>
<apass>?+gs)---F6n6a4AERi?e1s9n</apass>
</credentials>PowerShell script
try {
$username = '<API Token username>'
$password = '<API Token password>'
$hostname = 'dk-co.keepit.com'
$userId = '<Account GUID>'
$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"
"Accept" = "application/vnd.keepit.v1+xml"
}
$url = "https://$hostname/users/$userID/tokens/"
$xmlBody = @"
<token>
<acl>MasterAdmin</acl>
<descr>APIcustomtoken</descr>
<sessionkey/>
<primary>false</primary>
<lifetime>P1Y</lifetime>
</token>
"@
$response = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $xmlBody -ErrorAction Stop -TimeoutSec 10
$xml = [xml]$response.Content
Write-Host "username: $($xml.credentials.aname)"
Write-Host "password: $($xml.credentials.apass)"
}
catch {
$line = $_.InvocationInfo.ScriptLineNumber
Write-Host "Cannot query Keepit API due to: $_"
Write-Host "at line $line"
}
Script result
username: 7kHIy2%Sa@y!d4Q?t#-jty.(
password: pxvAaX,2G#rCfRs9YMwI)YAg
2. With assigned credentials
Body
<token>
<acl>MasterAdmin</acl>
<descr>APIcustomtoken</descr>
<aname>test@keepit.com</aname>
<apass>EnterYourPasswordHere!</apass>
<primary>false</primary>
<lifetime>P1Y</lifetime>
</token>
Response
Code: 201 Created
Response body
<credentials>
<aname>test@keepit.com</aname>
<apass>EnterYourPasswordHere!</apass>
</credentials>
PowerShell script
try {
$username = '<API Token username>'
$password = '<API Token password>'
$hostname = 'dk-co.keepit.com'
$userId = '<Account GUID>'
$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"
"Accept" = "application/vnd.keepit.v1+xml"
}
$url = "https://$hostname/users/$userID/tokens/"
$xmlBody = @"
<token>
<acl>MasterAdmin</acl>
<descr>APIcustomtoken</descr>
<aname>test@keepit.com</aname>
<apass>EnterYourPasswordHere!</apass>
<primary>false</primary>
<lifetime>P1Y</lifetime>
</token>
"@
$response = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $xmlBody -ErrorAction Stop -TimeoutSec 10
$xml = [xml]$response.Content
Write-Host "username: $($xml.credentials.aname)"
Write-Host "password: $($xml.credentials.apass)"
}
catch {
$line = $_.InvocationInfo.ScriptLineNumber
Write-Host "Cannot query Keepit API due to: $_"
Write-Host "at line $line"
}Script result
username: test@keepit.com
password: EnterYourPasswordHere!
Additional information
- To automatically generate the credentials, the following header must be included:
key – Accept
value - application/vnd.keepit.v1+xml
- The <primary> element determines whether the token is a Primary or Secondary token.
For secondary tokens, <primary> must be set to "false".
For primary tokens, <primary> must be set to "true". - Email notifications are not sent to secondary tokens. Notifications can be delivered only to primary tokens.