The following is a sample PowerShell script illustrating how to invoke a ServicePanel action form via the REST interface.
This sample assumes an on-premise Active Directory authenticated environment. Invoking a SaaS instance requires either obtaining an OAuth token, or using the Panel Client library to obtain an authentication header.
The following sample invokes a form called "CreateEmployee". In a typical setup this form would then trigger an insertion into the MIM Portal or a SQL table feeding into MIM or AD Connect.
PowerShell Script
# Sample script to call a basic Employee Creation action via ServicePanel REST Param( [string]$emplid, [string]$given, [string]$sn, [string]$address, [string]$city, [string]$state, [string]$postal, [string]$managerId, [string]$title, [Parameter(Mandatory=$False)] [string]$emplStatus="A", [Parameter(Mandatory=$False)] [string]$emplType="A", [Parameter(Mandatory=$False)] [string]$hireDt=(Get-Date -f yyyy-MM-dd) # Credential argument. Alternatively remove the argument and switch Invoke-RestMethod to use -UseDefaultCredential [Parameter(Mandatory=$False)] [PSCredential]$credential=(Get-Credential), [Parameter(Mandatory=$False)] [string]$restForm="CreateEmployee", [Parameter(Mandatory=$False)] [string]$uri="https://servicepanel.softwareidm.demo/api/serviceform", [Parameter(Mandatory=$False)] [string]$apiKey="Q8Oyh2mT2_XJfQ6RQGLlp_cxXnRO6jV4JMnb0qAdHJk~" ) $json = @{ Name=$restForm; Form=@{ UserInfo=@{ FIRST_NAME=$given; LAST_NAME=$sn; ADDRESS1=$address; CITY=$city; STATE=$state; POSTAL=$postal; }, JobInfo: { EMPLID=$emplid; SUPERVISOR_ID=$managerId; JOBTITLE=$title; EMPL_TYPE=$emplType; EMPL_STATUS=$emplStatus; HIRE_DT=$hireDt; EFFDT=$hireDt; } } } | ConvertTo-Json $headers = @{} $headers["X-Api-Key"] = $apiKey $response = Invoke-RestMethod $uri -Method Post -Credential $credential -Body $json -ContentType "application/json" -Headers $headers if ($response.Completed -eq $null){ Write-Host $response.Errors } else { Write-Host "Success" }
Comments
0 comments
Please sign in to leave a comment.