Get Connected Services Activity
Overviewβ
The Get Connected Services Activity (connected_services) activity in Pia Package Editor retrieves a list of Connected Services that have been configured for your tenant. This activity is useful in packages where the configuration of a connected service is required to perform certain action.
An example scenario where this activity can be used is in Pax8: Modify License Subscription Package. In order for the Package to perform the Pax8 license provisioning and deprovisioning task, it needs to check whether the Pax8 Connected Service has been configured for the tenant.
The Get Connected Services Activity can be located by searching for "Get Connected Services" in the list of activities in the package editor:
Below is the code snippet that shows how you can use the Get Connected Services activity to retrieve Connected Services Setup in your tenant:
# Pia Automation Package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Hello World'
lockTo: 1
steps:
- task: get_connected_services
- task: inline_powershell
alias: 'configured_conn_services'
inputs:
connservs: =connected_services.connected_services #this will be updated to =get_connected_services.connected_services
script: |
Write-Host $connservs
$cons = $(ConvertFrom-Json $connservs)
Activity Behaviourβ
The primary purpose of the Get Connected Services activity is to retrieve the stored connected service setup for your tenant.
The Get Connected Services Activity can be used in all package executions (i.e. packages that are initiated via Schedule or Ticketing System Event or the Chatbot).
Input Propertiesβ
There activity does not have any input properties.
Output Propertiesβ
There is a single property which the Get Connected Services activity makes available:
Property Name: connected_services
Property Description: This will return an object in JSON structure containing the connected service setup for the tenant.
Examplesβ
In the below example, an email is sent to the provided email address if the connected service for Office 365 Email has been configured for the tenant.
# Pia Automation Package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Hello World'
steps:
- task: get_connected_services
- task: inline_powershell
alias: 'configured_conn_services'
inputs:
connservs: =connected_services.connected_services #this will be updated to =get_connected_services.connected_services
script: |
Write-Host $connservs
$cons = $(ConvertFrom-Json $connservs)
if($cons.Name -contains "Office 365 Email"){
Write-Host "Office 365 Email is setup"
return @{stop = $false;}
}
return @{stop = $true}
- task: stop
inputs:
condition: =configured_conn_services.stop
- task: inline_powershell
alias: 'send_email'
inputs:
From: $o365_email_address
Token: $o365_email_graph_token
Body: "This is a test email"
Subject: "Testing Email - Pia"
#To: 'YOUREMAIL1@EXAMPLE.COM,YOUREMAIL2@EXAMPLE.COM' #Change this.
To: 'YOUREMAIL1@EXAMPLE.COM'
script: |
$headers = @{Authorization = "Bearer $token";}
$emailToMultiple = [Array]$("$To".split(",").Trim() | Where-Object { -not [string]::IsNullOrEmpty($_) })
$requestBody = @{
"message" = @{
"subject" = "$Subject"
"body" = [PSCustomObject]@{
"contentType" = "Text"
"content" = "$Body"
}
"toRecipients" = @(
)
}
"saveToSentItems" = "true"
}
foreach($em in $emailToMultiple){
$requestBody.message.toRecipients += [PSCustomObject]@{
"emailAddress" = [PSCustomObject]@{
"address" = $em
}
}
}
$sendEmail = Invoke-RestMethod `
-Uri 'https://graph.microsoft.com/v1.0/me/sendMail' `
-Method POST `
-Headers $headers `
-Body $(ConvertTo-Json $requestBody -Depth 10 -Compress) `
-ContentType "application/json"