Manage xDM plaform with powershell
Since Semarchy xDM V5, web service (REST API) are available to manage Semarchy xDM platform.
This Article give you some sample that you can use to write your own command to manage your platform.
Get Platform Status
$user = "semadmin"
$pass = "semadmin"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Header = @{Authorization = $basicAuthValue}
$url = "http://localhost:8088/semarchy/api/rest/admin/status"
Invoke-RestMethod -Uri $url -Header $Header | ConvertTo-Json
Get repository Information
$user = "semadmin"
$pass = "semadmin"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Header = @{Authorization = $basicAuthValue}
$url = "http://localhost:8088/semarchy/api/rest/admin/repository"
Invoke-RestMethod -Uri $url -Header $Header | ConvertTo-Json
Create a New model
$user = "semadmin"
$pass = "semadmin"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Header = @{Authorization = $basicAuthValue}
$url = "http://localhost:8088/semarchy/api/rest/app-builder/models"
$model = @{name= "myDemo"
label= "my demo model"
description= "my demo model description"
branch= @{
name= "mybranch"
label= "my branch label"
description= "my first branch"
}}
$body = (ConvertTo-Json $model)
Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType 'application/json' -Header $Header
Export model Edition
$user = "semadmin"
$pass = "semadmin"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Header = @{Authorization = $basicAuthValue}
$url = get-content .\URL.txt
$url = $url + "/api/rest/app-builder/models/Winoa/editions/0.0/content"
Invoke-RestMethod -Uri $url -Method get -Header $Header -OutFile export.xml
Complete Sample to import a model on a DEV environement
#connection to xDM using basic authentification
$user = "semadmin"
$pass = "semadmin"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Header = @{Authorization = $basicAuthValue}
#-------------------------------------------------------------------------------------------------------
#call the Rest API to create a new model
#-------------------------------------------------------------------------------------------------------
#Build the URL
#base url is stored in URL.txt (http://localhost:8088/semarchy)
$baseurl = get-content .\URL.txt
$url = $baseurl + "/api/rest/app-builder/models"
#first step is to build the payload (aka the body)
$model = @{name= "Winoa"
label= "my demo model"
description= "my demo model description"
branch= @{
name= "mybranch"
label= "my branch label"
description= "my first branch"
}}
$body = (ConvertTo-Json $model)
# Call the Rest API to create the model with the good payload in the good content type
Write-Output "1 - Creating the model ....."
Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType 'application/json' -Header $Header
#-------------------------------------------------------------------------------------------------------
#call the Rest API to import the model
#-------------------------------------------------------------------------------------------------------
#build the URL
$url = $baseurl + "/api/rest/app-builder/models/Winoa/editions/0.0/content"
# Call the rest API to import the model with the good content type
Write-Output "2 - Import the model ....."
$model = get-content .\export.xml -Raw
Invoke-RestMethod -Uri $url -Method Post -Header $Header -Body $model -ContentType "application/octet-stream"
#--------------------------------------------------------------------------------------------------------
#Call the Rest Api to create a Datalocation
#--------------------------------------------------------------------------------------------------------
#Build the URL
$url = $baseurl + "/api/rest/app-builder/data-locations"
#Build the payload
$dataloc = @{name= "Cust"
type= "DEV"
label= "ma dataloc"
description= "my test dataloc create by Rest API"
dataSource= "java:comp/env/jdbc/CUSTOMER"
modelName= "Winoa"
modelEditionKey= "0.0"
}
$body = (ConvertTo-Json $dataloc)
#Call the Rest API to create the dataloc
Write-Output "3 - Create the Data Location ....."
Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType 'application/json' -Header $Header