Since Semarchy xDM v5, web services (REST API) are available to manage the Semarchy xDM platform.

This article gives you some Powershell commands that you can use to write your own commands and manage your platform. Alternatively, you can create your requests in a REST client such as Postman.

Common commands - authentication parameters

Before calling any service, always run the following commands:


#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}
$host = "localhost"
$port = "8088"
$base_url = "http://$($host):$($port)"
 

Replace semadmin credentials, host and port with the correct values for your xDM environment.

Get platform status

In addition to the commands listed above, execute the following ones:


$url = $base_url + "/semarchy/api/rest/admin/status"_
Invoke-RestMethod -Uri $url -Header $header | ConvertTo-Json
 

Get repository information


$url = $base_url + "/semarchy/api/rest/admin/repository"
Invoke-RestMethod -Uri $url -Header $header | ConvertTo-Json
 

Create a New model


$url = $base_url + "/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


$url = $base_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 environment

1. Call authentication commands (see above)

2. Call the Rest API to create a new model

$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 
 

3. 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"
 

4. Call the Rest API to create a Data Location


#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