Admin API
Die Admin API stellt Schnittstellen zum Benutzer-, Profil- und Organisations-Management zur Verfügung.
Authentifizierung
Um die Admin APIs aufzurufen, muss in der primedocs.config solch ein Client registriert sein, siehe hierfür primedocs.config.
Nach der Registrierung kann damit ein AccessToken vom IdS angefordert werden.
Dieses PowerShell-Beispiel zeigt den Bezug des AccessTokens:
# Configuration
$datasourceId = "b78c3707-d7c7-4fc7-b97f-87d70f63c1ac"
$tokenUrl = "https://primedocs.example.org/ids/connect/token"
$clientID = "CustomApiClient"
$clientSecret = "CustomClient_Secret_123"
$scope = "pd_AdminWebApi"
$tokenRequestHeaders = @{
"Content-Type" = "application/x-www-form-urlencoded"
}
$tokenRequestBody = @{
client_id = $clientID
client_secret = $clientSecret
grant_type = "client_credentials"
scope = $scope
}
# Request the access token
try {
$tokenResponse = Invoke-RestMethod -Uri $tokenUrl -Method POST -Headers $tokenRequestHeaders -Body $tokenRequestBody
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
if (-not $tokenResponse.access_token) {
Write-Error "Failed to obtain an access token!"
exit 1
}
# Access token information
Write-Host "Access Token: $($tokenResponse.access_token)"
$accessToken = $tokenResponse.access_tokenQuery-Syntax
Die Admin API bietet typische “CRUD” (Create / Read / Update / Delete) Endpunkte als HTTP API an.
Um Daten gezielt zu suchen, bieten folgende GET-Endpunkte einen “query” Parameter an:
HTTP GET-Endpunkt | Beschreibung |
|---|---|
| Gibt eine Liste von “AppUserGroups” zurück. |
| Gibt eine Liste von “UserGroups” zurück. |
| Gibt eine Liste von “Users” zurück. |
| Gibt eine Liste von “Templates” zurück. |
Alle diese APIs geben paginierte Liste der Daten zurück. Über den “Query”-Parameter kann eine Filterung/Suche ausgelöst werden.
Der Syntax setzt sich aus [Eigenschaft]:"[Filter]" [WeitereEigenschaft]:"[Weiterer Filter]"... zusammen.
" können optional um den Filter gesetzt werden - insbesondere wenn Leerzeichen Teil des Filterkriterium sind.
Einige Eigenschaften unterstützten den *-Wildcard Operator am Anfang und Ende.
Die einzelnen Filter sind UND-verknüpft.
Beispiel:
https://primedocs.example.org/webapi/api/v3/{datasourceId}/Admin/Templates?query=localizedName:*brief%20active:true
Sucht alle aktiven Vorlagen, wessen Namen mit “brief” endet.
AppUserGroups
Mögliche “Query”-Optionen:
title: Suche nach TitelUnterstützt den
*-Wildcard Operator am Anfang und Ende.
primarySid: Suche nach der PrimarySidUnterstützt den
*-Wildcard Operator am Anfang und Ende.
Beispiel:
title:Admin primarySid:123* = Sucht alle AppUserGroups welche den Titel “Admin” tragen und mit der primarySid 123 beginnen.
UserGroups
Mögliche “Query”-Optionen:
title: Suche nach TitelUnterstützt den
*-Wildcard Operator am Anfang und Ende.
primarySid: Suche nach der PrimarySidUnterstützt den
*-Wildcard Operator am Anfang und Ende.
Beispiel:
title:Admin primarySid:123* = Sucht alle UserGroups welche den Titel “Admin” tragen und mit der primarySid 123 beginnen.
Users
Mögliche “Query”-Optionen:
title: Suche nach TitelUnterstützt den
*-Wildcard Operator am Anfang und Ende.
primarySid: Suche nach der PrimarySidUnterstützt den
*-Wildcard Operator am Anfang und Ende.
field[<User.FieldId>]: Suche nach einem konfigurierbaren Benutzerfeld (z.B.field[User.FirstName])Unterstützt den
*-Wildcard Operator am Anfang und Ende.
Beispiel:
title:"John*" Field[User.EmailField]:"*foobar.com" = Sucht alle Users welche im Titel am Anfang “John” stehen haben und im Benutzerfeld User.EmailField die E-Mail-Adresse mit foobar.com endet.
Templates
Mögliche “Query”-Optionen:
templateId: Suche nach der TemplateIdMuss eine GUID sein.
metaTemplateId: Suche nach der MetaTemplateIdMuss eine GUID sein.
active: Suche nach aktiven/inaktiven (gelöschten) VorlagenMuss ein Bool (
True,False) sein.
templatestate: Suche nach dem Vorlagen StatusUnterstützt: 0 (=
InProgress), 1 (=InTest), 2 (=Released)
templateGroupId: Suche nach der übergeordneten Vorlagen GruppeMuss eine GUID sein.
localizedName: Suche nach dem Namen.Unterstützt den
*-Wildcard Operator am Anfang und Ende.
localizedDescription: Suche nach der Beschreibung.Unterstützt den
*-Wildcard Operator am Anfang und Ende.
tags: Suche nach TagsUND-Verknüpfung über
;und ODER-Verknüpfung über|. (BeispielTAG1;TAG2;TAG3|TAG4)
Beispiel:
active:true tags:ProjectX;Finance|Controlling = Sucht alle aktiven Templates, welche entweder getaggt sind mit ProjectX und Finance oder welche den Tag Controlling haben.
Beispiele
Dieses AccessToken muss bei allen Aufrufen in den Authorization-Header mitgegeben werden. Die API lässt aktuell das Auflisten, Anlegen und Bearbeiten von Benutzern zu. Nachfolgend sind Beispiele zu finden:
Benutzer auflisten
Damit werden vorhandene Benutzer aufgelistet:
# Prepare headers for request
$apiRequestHeaders = @{
"Authorization" = "Bearer $accessToken"
}
Write-Host "Getting users..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
try {
$apiUrl = "https://primedocs.example.org/webapi/api/v3/$($datasourceId)/Admin/Users?pageSize=$($pageSize)&page=$($page)"
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($user in $response.data) {
Write-Output "$($user.id): '$($user.title)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}Benutzer-Onboarding
Über diesen Aufruf kann ein neuer Benutzer anhand der SID hinzugefügt werden. Es wird dann automatisch der Benutzer Onboarding & Offboarding Prozess durchlaufen.
# Prepare headers for request
$apiRequestHeaders = @{
"Authorization" = "Bearer $accessToken"
}
$sid = Read-Host "Enter SID"
Write-Host "Creating and onboarding user with SID: $sid"
try {
$apiUrl = "https://primedocs.example.org/webapi/api/v3/$($datasourceId)/Admin/Users?sid=" + $sid;
$user = Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $apiRequestHeaders
Write-Output "Onboarded '$($user.title)' with id '$($user.id)'";
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}PowerShell Script
Nachfolgend finden Sie ein vollständiges Beispiel PowerShell Script (für die Version 4.0.30100.0), welches verschiedene UseCases abdeckt.
Der Abschnitt Configuration (datasourceId, tokenUrl, baseApiUrl, clientId und clientSecret) muss geändert werden auf die Einstellung der jeweiligen Umgebung.
# Configuration
$datasourceId = "b78c3707-d7c7-4fc7-b97f-87d70f63c1ac"
$tokenUrl = "https://localhost:5020/connect/token"
$baseApiUrl = "https://localhost:5001/api"
$clientID = "ApiClient"
$clientSecret = "Client_Secret_123"
$scope = "pd_AdminWebApi"
$tokenRequestHeaders = @{
"Content-Type" = "application/x-www-form-urlencoded"
}
$tokenRequestBody = @{
client_id = $clientID
client_secret = $clientSecret
grant_type = "client_credentials"
scope = $scope
}
# Request the access token
try {
$tokenResponse = Invoke-RestMethod -Uri $tokenUrl -Method POST -Headers $tokenRequestHeaders -Body $tokenRequestBody
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
if (-not $tokenResponse.access_token) {
Write-Error "Failed to obtain an access token!"
exit 1
}
# Access token information
Write-Host "Access Token: $($tokenResponse.access_token)"
$accessToken = $tokenResponse.access_token
# Prepare headers for request
$apiRequestHeaders = @{
"Authorization" = "Bearer $accessToken"
}
$putBodyRequestHeaders = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer $accessToken"
}
function Show-Menu {
Write-Host "================ Main Menu ================"
Write-Host "1: Get Users"
Write-Host "2: Get User Details"
Write-Host "3: Update User"
Write-Host "4: Create and Onboard User"
Write-Host "5: Get Profile"
Write-Host "6: Profile Update"
Write-Host "7: Add Profile Share"
Write-Host "8: Delete Profile Share"
Write-Host "9: Create and Onboard Group"
Write-Host "10: Get Groups"
Write-Host "11: Get Organization Units"
Write-Host "12: Get Organization Unit Details"
Write-Host "13: Get Organization Unit Children"
Write-Host "14: Update Organization Unit"
Write-Host "15: Get Snippet Groups"
Write-Host "16: Get Snippet Group Details"
Write-Host "17: Create Snippet Group"
Write-Host "18: Delete Snippet Group"
Write-Host "19: Get Snippet Group Children"
Write-Host "20: Update Snippet Group ParentId or Sort"
Write-Host "21: Delete Snippet Group Permission"
Write-Host "22: Add Snippet Group Permission"
Write-Host "23: Delete Snippet Group Localization"
Write-Host "24: Add Snippet Group Localization"
Write-Host "25: Get AppUserGroups"
Write-Host "26: Get Templates"
Write-Host "Q: Exit"
}
function GetUsers {
Write-Host "Getting users..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
$query = Read-Host "Enter query"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users?pageSize=$($pageSize)&page=$($page)"
# Append query only if it's not null or whitespace
if (![string]::IsNullOrWhiteSpace($query)) {
$apiUrl += "&query=$query"
}
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($user in $response.data) {
Write-Output "$($user.id): '$($user.title)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetUserDetails {
$userId = Read-Host "Enter UserId"
Write-Host "Getting details for user: $userId"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users/" + $userId;
$user = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
Write-Output "Id: '$($user.id)'"
Write-Output "Title: '$($user.title)'";
Write-Output "Profiles: "
foreach ($profile in $user.profiles) {
Write-Output "'$($profile.id)': '$($profile.title) (Profile OU: '$($profile.organizationUnitId)')"
}
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function CreateAndOnBoardUser {
$sid = Read-Host "Enter SID"
Write-Host "Creating and onboarding user with SID: $sid"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users?sid=" + $sid;
$user = Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $apiRequestHeaders
Write-Output "Onboarded '$($user.title)' with id '$($user.id)'";
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function CreateAndOnBoardGroup {
$sid = Read-Host "Enter SID"
Write-Host "Creating and onboarding Group with SID: $sid"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Groups?sid=" + $sid;
$group = Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $apiRequestHeaders
Write-Output "Onboarded '$($group.title)' with id '$($group.id)'";
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetGroups {
Write-Host "Getting Groups..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
$query = Read-Host "Enter query"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Groups?pageSize=$($pageSize)&page=$($page)"
# Append query only if it's not null or whitespace
if (![string]::IsNullOrWhiteSpace($query)) {
$apiUrl += "&query=$query"
}
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($group in $response.data) {
Write-Output "$($group.id): '$($group.title)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetAppUserGroups {
Write-Host "Getting AppUserGroups..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
$query = Read-Host "Enter query"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/AppUserGroups?pageSize=$($pageSize)&page=$($page)"
# Append query only if it's not null or whitespace
if (![string]::IsNullOrWhiteSpace($query)) {
$apiUrl += "&query=$query"
}
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($group in $response.data) {
Write-Output "$($group.id): '$($group.title)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetTemplates {
Write-Host "Getting Templates..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
$query = Read-Host "Enter query"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Templates?pageSize=$($pageSize)&page=$($page)"
# Append query only if it's not null or whitespace
if (![string]::IsNullOrWhiteSpace($query)) {
$apiUrl += "&query=$query"
}
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($template in $response.data) {
Write-Output "$($template.templateId): MetaTemplateId: '$($template.metaTemplateId)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function ProfileUpdate {
$userId = Read-Host "Enter User ID"
$profileId = Read-Host "Enter Profile ID"
$title = Read-Host "Enter Title"
$organizationUnitId = Read-Host "Enter New Organization Unit ID"
$lcid = 1031 #Read-Host "Enter lcid"
$field = "Org.Title" # Read-Host "Enter Field"
$field2 = "User.FirstName" # Read-Host "Enter Field"
$text = Read-Host "Enter New Org.Title Value (Empty = delete)"
$text2 = Read-Host "Enter New User.FirstName Value (Empty = delete)"
Write-Host "Updating profile for User ID: $userId, Profile ID: $profileId, Title: $title, Organization Unit ID: $organizationUnitId"
$targetOrganizationUnitId = if ($null -ne $organizationUnitId) {
[System.Guid]::Parse($organizationUnitId)
} else {
$null
}
try {
$body = @{
Title = $title;
OrganizationUnitId = $targetOrganizationUnitId;
FieldChanges = @(
@{
Lcid = $lcid
Field = $field
Text = $text
Purge = ($text -eq "")
},
@{
Lcid = $lcid
Field = $field2
Text = $text2
Purge = ($text2 -eq "")
}
)
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users/$($userId)/Profiles/$($profileId)";
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method PUT -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetProfile {
$userId = Read-Host "Enter User ID"
$profileId = Read-Host "Enter Profile ID"
Write-Host "Getting profile for User ID: $userId, Profile ID: $profileId"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users/" + $userId + "/Profiles/" + $profileId;
$userProfile = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
Write-Output "Id: '$($userProfile.id)'"
Write-Output "Title: '$($userProfile.title)'";
Write-Output "ProfileShares: "
foreach ($share in $userProfile.profileShares) {
if ($null -ne $share.userId) {
Write-Output "'$($share.id)': UserId:'$($share.userId)', ProfilePermissionLevel:'$($share.profilePermissionLevel)', SignaturePermissionLevel:'$($share.signaturePermissionLevel)'"
}
if ($null -ne $share.groupId) {
Write-Output "'$($share.id)': GroupId:'$($share.groupId)', ProfilePermissionLevel:'$($share.profilePermissionLevel)', SignaturePermissionLevel:'$($share.signaturePermissionLevel)'"
}
if ($null -ne $share.appUserGroupId) {
Write-Output "'$($share.id)': AppUserGroupId:'$($share.appUserGroupId)', ProfilePermissionLevel:'$($share.profilePermissionLevel)', SignaturePermissionLevel:'$($share.signaturePermissionLevel)'"
}
}
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function AddProfileShare {
$userId = Read-Host "Enter User ID"
$profileId = Read-Host "Enter Profile ID"
Write-Host "Enter either User ID or Group ID or AppUserGroup ID to access the profile. Leave two of them empty."
$shareUserId = Read-Host "Enter User ID (or empty)"
$shareGroupId = Read-Host "Enter Group ID (or empty)"
$shareAppUserGroupId = Read-Host "Enter AppUserGroup ID (or empty)"
Write-Host " "
Write-Host "0: Profile share cannot be used as 'regular' profile"
Write-Host "1: Profile share can be used as 'regular' profile, but will be marked 'on behalf'"
Write-Host "2: Profile share can be used as 'regular' profile and impersonation is allowed"
$profilePermissionLevel = Read-Host "Enter Profile Permission Level"
Write-Host " "
Write-Host "0: Signature share cannot be used for document signing"
Write-Host "1: Signature share can be used for document signing, but without real signature image"
Write-Host "2: Signature share can be used for document signing with real signature image"
$signaturePermissionLevel = Read-Host "Enter Signature Permission Level"
$targetShareUserId = if ($shareUserId -eq "") {
$null
} else {
$shareUserId
}
$targetShareGroupId = if ($shareGroupId -eq "") {
$null
} else {
$shareGroupId
}
$targetShareAppUserGroupId = if ($shareAppUserGroupId -eq "") {
$null
} else {
$shareAppUserGroupId
}
try {
$body = @{
UserId = $targetShareUserId
GroupId = $targetShareGroupId
AppUserGroupId = $targetShareAppUserGroupId
profilePermissionLevel = $profilePermissionLevel
signaturePermissionLevel = $signaturePermissionLevel
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users/$($userId)/Profiles/$($profileId)/ProfileShares";
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function DeleteProfileShare {
$userId = Read-Host "Enter User ID"
$profileId = Read-Host "Enter Profile ID"
$profileShareId = Read-Host "Enter Profile Share ID"
Write-Host "Deleting profile share for User ID: $userId, Profile ID: $profileId, Profile Share ID: $profileShareId"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users/$($userId)/Profiles/$($profileId)/ProfileShares/$($profileShareId)";
Invoke-RestMethod -Uri $apiUrl -Method DELETE -Headers $putBodyRequestHeaders
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetOrganizationUnits {
Write-Host "Getting organization units..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/OrganizationUnits?pageSize=$($pageSize)&page=$($page)";
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($organizationUnit in $response.data) {
Write-Output "$($organizationUnit.id): '$($organizationUnit.title)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetOrganizationUnitDetails {
$organizationUnitId = Read-Host "Enter Organization Unit ID"
Write-Host "Getting details for organization unit: $organizationUnitId"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/OrganizationUnits/" + $organizationUnitId;
$organizationUnit = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
Write-Output "Id: '$($organizationUnit.id)'"
Write-Output "Title: '$($organizationUnit.title)'";
Write-Output "ParentId: '$($organizationUnit.parentId)'";
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetOrganizationUnitChildren {
$organizationUnitId = Read-Host "Enter Organization Unit ID"
Write-Host "Getting children for organization unit: $organizationUnitId"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/OrganizationUnits/" + $organizationUnitId + "/Children";
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($organizationUnit in $response.data) {
Write-Output "$($organizationUnit.id): '$($organizationUnit.title)'"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function UpdateOrganizationUnit {
Write-Host "Updating organization unit"
$organizationUnitId = Read-Host "Enter Organization Unit ID"
$title = Read-Host "Enter New Title"
$parentOrganizationUnitId = Read-Host "Enter New Parent Organization Unit ID"
$lcid = 1031 #Read-Host "Enter lcid"
$field = "Org.Title" # Read-Host "Enter Field"
$field2 = "Org.Claim" # Read-Host "Enter Field"
$text = Read-Host "Enter New Org.Title Value (Empty = delete)"
$text2 = Read-Host "Enter New Org.Claim Value (Empty = delete)"
Write-Host "Updating organization unit, Title: $title, Organization Unit ID: $organizationUnitId"
$targetParentOrganizationUnitId = if ($null -ne $parentOrganizationUnitId) {
[System.Guid]::Parse($parentOrganizationUnitId)
} else {
$null
}
try {
$body = @{
Title = $title
OrganizationUnitParentId = $targetParentOrganizationUnitId
FieldChanges = @(
@{
Lcid = $lcid
Field = $field
Text = $text
Purge = ($text -eq "")
},
@{
Lcid = $lcid
Field = $field2
Text = $text2
Purge = ($text2 -eq "")
}
)
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/OrganizationUnits/$($organizationUnitId)";
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method PUT -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function UpdateUser {
$userId = Read-Host "Enter User ID"
$title = Read-Host "Enter New Title"
$lcid = 1031 #Read-Host "Enter lcid"
$field = "User.FirstName" # Read-Host "Enter Field"
$field2 = "User.LastName" # Read-Host "Enter Field"
$text = Read-Host "Enter New User.FirstName Value (Empty = delete)"
$text2 = Read-Host "Enter New User.LastName Value (Empty = delete)"
Write-Host "Updating user, Title: $title, User ID: $userId"
try {
$body = @{
Title = $title
FieldChanges = @(
@{
Lcid = $lcid
Field = $field
Text = $text
Purge = ($text -eq "")
},
@{
Lcid = $lcid
Field = $field2
Text = $text2
Purge = ($text2 -eq "")
}
)
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/Users/$($userId)";
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method PUT -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetSnippetGroups {
Write-Host "Getting snippet groups (public)..."
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/?pageSize=$($pageSize)&page=$($page)";
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($snippetGroup in $response.data) {
Write-Output "$($snippetGroup.id)"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetSnippetGroupsChildren {
Write-Host "Getting snippet groups (public)..."
$parentSnippetGroup = Read-Host "Enter Parent Snippet Group"
$pageSize = Read-Host "Enter pagesize"
$page = Read-Host "Enter page"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($parentSnippetGroup)/SnippetGroups?pageSize=$($pageSize)&page=$($page)";
$response = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
foreach ($snippetGroup in $response.data) {
Write-Output "$($snippetGroup.id)"
}
Write-Output "Page: $($response.pagingDetails.page) / $($response.pagingDetails.totalPages)"
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function GetSnippetGroupDetails {
Write-Host "Getting snippet groups (public) for id..."
$snippetGroup = Read-Host "Enter Snippet Group ID"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($snippetGroup)";
$snippetGroup = Invoke-RestMethod -Uri $apiUrl -Method GET -Headers $apiRequestHeaders
Write-Output "Id: '$($snippetGroup.id)'"
Write-Output "ParentId: '$($snippetGroup.parentId)'"
Write-Output "Sort: '$($snippetGroup.sort)'"
Write-Output "Localized Data:"
foreach ($localized in $snippetGroup.localized) {
Write-Output "Localized '$($localized.lcid)': Name '$($localized.name)' | Description '$($localized.description)' | SearchKeywords '$($localized.searchkeywords)'"
}
Write-Output "Permissions:"
foreach ($permission in $snippetGroup.permissions) {
Write-Output "Permission '$($permission.id)': UserId '$($permission.userId)' | GroupId '$($permission.groupid)' | AppUserGroupId '$($permission.appUserGroupId)' | HasModifyPermission: '$($permission.HasModifyPermission)' | HasUsingPermission: '$($permission.HasUsingPermission)'"
}
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function CreateSnippetGroup {
$parentId = Read-Host "Enter Snippet Parent Id (or empty)"
Write-Host "Enter either User ID or Group ID or AppUserGroup ID to give use and modify permission on the snippetgroup. Leave two of them empty."
$shareUserId = Read-Host "Enter User ID (or empty)"
$shareGroupId = Read-Host "Enter Group ID (or empty)"
$shareAppUserGroupId = Read-Host "Enter AppUserGroup ID (or empty)"
$targetShareUserId = if ($shareUserId -eq "") {
$null
} else {
$shareUserId
}
$targetShareGroupId = if ($shareGroupId -eq "") {
$null
} else {
$shareGroupId
}
$targetShareAppUserGroupId = if ($shareAppUserGroupId -eq "") {
$null
} else {
$shareAppUserGroupId
}
$targetParentSnippetGroupId = if ($parentId -eq "") {
$null
} else {
[System.Guid]::Parse($parentId)
}
$lcid = Read-Host "Enter lcid"
$name = Read-Host "Enter Sample Name"
# Sort can also be applied
try {
$body = @{
ParentId = $targetParentSnippetGroupId
Localized = @(
@{
Lcid = $lcid
Name = $name
}
)
Permissions = @(
@{
UserId = $targetShareUserId
GroupId = $targetShareGroupId
AppUserGroupId = $targetShareAppUserGroupId
HasModifyPermission = $true
HasUsingPermission = $true
}
)
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/";
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function DeleteSnippetGroup {
$snippetGroup = Read-Host "Enter SnippetGroup ID"
Write-Host "Deleting public snippet group (and everything below) for Snippet Group ID: $snippetGroup"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($snippetGroup)";
Invoke-RestMethod -Uri $apiUrl -Method DELETE -Headers $putBodyRequestHeaders
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function UpdateSnippetGroup {
$targetSnippetGroup = Read-Host "Enter Snippet Group Id which needs to be updated"
$parentId = Read-Host "Enter new Snippet Group Parent Id"
$sort = Read-Host "Enter Sort"
$targetParentSnippetGroupId = if ($parentId -eq "") {
$null
} else {
[System.Guid]::Parse($parentId)
}
try {
$body = @{
ParentId = $targetParentSnippetGroupId
Sort = $sort
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($targetSnippetGroup)";
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method PUT -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function DeleteSnippetGroupPermission {
$targetSnippetGroup = Read-Host "Enter Snippet Group Id which needs to be updated"
$targetSnippetGroupPermissionId = Read-Host "Enter Permission Id"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($targetSnippetGroup)/Permissions/$($targetSnippetGroupPermissionId)";
Invoke-RestMethod -Uri $apiUrl -Method DELETE -Headers $putBodyRequestHeaders
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function AddSnippetGroupPermission {
$targetSnippetGroupId = Read-Host "Enter Snippet Group Id"
Write-Host "Enter either User ID or Group ID or AppUserGroup ID to give use and modify permission on the snippetgroup. Leave two of them empty."
$shareUserId = Read-Host "Enter User ID (or empty)"
$shareGroupId = Read-Host "Enter Group ID (or empty)"
$shareAppUserGroupId = Read-Host "Enter AppUserGroup ID (or empty)"
$targetShareUserId = if ($shareUserId -eq "") {
$null
} else {
$shareUserId
}
$targetShareGroupId = if ($shareGroupId -eq "") {
$null
} else {
$shareGroupId
}
$targetShareAppUserGroupId = if ($shareAppUserGroupId -eq "") {
$null
} else {
$shareAppUserGroupId
}
try {
$body = @{
UserId = $targetShareUserId
GroupId = $targetShareGroupId
AppUserGroupId = $targetShareAppUserGroupId
HasModifyPermission = $true
HasUsingPermission = $true
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($targetSnippetGroupId)/Permissions"
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function DeleteSnippetGroupLocalization {
$targetSnippetGroup = Read-Host "Enter Snippet Group Id which needs to be updated"
$targetSnippetGroupLcid = Read-Host "Enter Localization LCID"
try {
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($targetSnippetGroup)/Localized/$($targetSnippetGroupLcid)";
Invoke-RestMethod -Uri $apiUrl -Method DELETE -Headers $putBodyRequestHeaders
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
function AddSnippetGroupLocalization {
$targetSnippetGroupId = Read-Host "Enter Snippet Group Id"
$lcid = Read-Host "Enter lcid"
$name = Read-Host "Enter Name"
$description = Read-Host "Enter Description"
$searchKeyWord = Read-Host "Enter SearchKeywords"
try {
$body = @{
Lcid = $lcid
Name = $name
Description = $description
SearchKeywords = $searchKeyWord
}
$apiUrl = "$($baseApiUrl)/v3/$($datasourceId)/Admin/SnippetGroups/Public/$($targetSnippetGroupId)/Localized"
# Ensure UTF-8 Encoding
$utf8body = ([System.Text.Encoding]::UTF8.GetBytes(($body | ConvertTo-Json)))
Invoke-RestMethod -Uri $apiUrl -Method POST -Headers $putBodyRequestHeaders -Body $utf8body
}
catch {
Write-Error "Error making the request: $_"
exit 1;
}
}
do {
Show-Menu
$selection = Read-Host "Please select an option"
switch ($selection) {
'1' { GetUsers }
'2' { GetUserDetails }
'3' { UpdateUser }
'4' { CreateAndOnBoardUser }
'5' { GetProfile }
'6' { ProfileUpdate }
'7' { AddProfileShare }
'8' { DeleteProfileShare }
'9' { CreateAndOnBoardGroup }
'10' { GetGroups }
'11' { GetOrganizationUnits }
'12' { GetOrganizationUnitDetails }
'13' { GetOrganizationUnitChildren }
'14' { UpdateOrganizationUnit }
'15' { GetSnippetGroups }
'16' { GetSnippetGroupDetails }
'17' { CreateSnippetGroup }
'18' { DeleteSnippetGroup }
'19' { GetSnippetGroupsChildren }
'20' { UpdateSnippetGroup }
'21' { DeleteSnippetGroupPermission }
'22' { AddSnippetGroupPermission }
'23' { DeleteSnippetGroupLocalization }
'24' { AddSnippetGroupLocalization }
'25' { GetAppUserGroups }
'26' { GetTemplates }
'Q' { break; }
Default {
Write-Host "Invalid option selected"
}
}
} while ($selection -ne 'Q')
Swagger / Open API
Die aktuelle Admin API Open API kann z.B. von der PrimeSoft Instanz als Referenz genutzt werden:
https://primesoft.primedocs.io/webapi/swagger/index.html
Sie können diese Beschreibung z.B. über den Swagger Editor visualisieren.
PrimeSoft AG, Bahnhofstrasse 4, 8360 Eschlikon, Switzerland