Need

REST APIs are available to manage and automate several xDM platform operations.

These APIs can be useful when you need to:

  • Check the platform status.
  • Retrieve repository information.
  • Create models programmatically.
  • Export model editions.
  • Import model content.
  • Create data locations.
  • Automate environment setup, especially for DEV or test environments.
  • ...

Instead of performing all actions manually in the UI, administrators or technical users can use PowerShell scripts to call the REST APIs.

Alternatively, the same REST requests can be created and tested using REST clients such as Postman.


Summarized Solution

To manage the xDM platform using REST API and PowerShell:

  • Define connection and authentication parameters.
  • Build the REST API URL using the xDM host and port.
  • Prepare the HTTP headers.
  • Call the required REST endpoint using Invoke-RestMethod.
  • Provide JSON or XML payloads when required.
  • Use the response to validate the operation.


Detailed Solution

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)"
 #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)" #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