Hi community
I hope that you can shed some light on this issue.
I have set up a (relatively simple) connector to a system called LogBuy - It's like an Employee benefits portal where customers gets discount. The API only support creation and deletion of accounts, there is no read-support in the API whatsoever.
I have set everything up as a custom target system, using the powershell connector. It creates fine, and the process for deletion also runs, but it doesn't execute the Delete function in the Template when it deprovisions. I don't get any errors, the job runs succesfully. I can see that it runs the initialization function but then nothing happens. I've tried everything I can think of to get it to run the function but it just doesn't get to that point.
I use the built-on processes DSI_UNSAccountB_Insert and DSI_UNSAccountB_Delete for provisioning and deprovisioning. I have Single Object Operations for both Insert and Delete. My workflow in the sync-project is configured for both Insert and Delete. (and it works just fine for insert)
Anyone knows why it doesn't run my Remove-LogBuyUser?
<?xml version="1.0" encoding="utf-16"?>
<PowershellConnectorDefinition Id="SampleGeneratedConnector" Version="1.0" Description="Powershell Generated Connector using PowerShell Module">
<PluginAssemblies />
<!--======Connection Parameter================
-->
<ConnectionParameters>
<ConnectionParameter Name="AppURI" Description="Application URI" IsSensibleData="false" />
<ConnectionParameter Name="AuthURI" Description="Authentication URI" IsSensibleData="false" />
<ConnectionParameter Name="AppSecret" Description="Application Secret" IsSensibleData="false" />
<ConnectionParameter Name="CustomerId" Description="Customer ID" IsSensibleData="false" />
</ConnectionParameters>
<!--======Initialization================
-->
<Initialization>
<!--======Custom Commands=================================
-->
<CustomCommands>
<CustomCommand Name="Get-LogBuyAuthenticationHeaders">
<![CDATA[
[CmdletBinding()]
[OutputType([String])]
param
(
[parameter(Mandatory = $true)]
[string]$AuthUrl,
[parameter(Mandatory = $true)]
[string]$CustomerId,
[parameter(Mandatory = $true)]
[string]$AppKey
)
process
{
try
{
$authBody = @{
grant_type = "accessbykey"
username = ""
password = ""
accesskey = $($AppKey)
}
$authToken = Invoke-RestMethod -Method 'Post' -Uri $authUrl -Body $authBody
$authHeaders = @{
"Content-Type" = "application/json; charset=utf-8"
Authorization = "Bearer "+$authToken.access_token
}
Return $authHeaders
}
catch
{
throw
}
}
]]>
</CustomCommand>
<CustomCommand Name="Get-LogBuyUser">
<![CDATA[
[CmdletBinding()]
[OutputType([String])]
param(
$Email
)
process
{
return @{
Email = $email
FirstName = ""
Surname = ""
SalaryNumber = ""
Gender = 0
}
}
]]>
</CustomCommand>
<CustomCommand Name="Get-LogBuyUsers">
<![CDATA[
[CmdletBinding()]
[OutputType([String])]
param(
)
process
{
return @()
}
]]>
</CustomCommand>
<CustomCommand Name="Remove-LogBuyUser">
<![CDATA[
[CmdletBinding()]
[OutputType([String])]
param(
[parameter(Mandatory = $true)]
[string]$Email
)
process
{
Add-Content -Path "LogBuyDebug.log" -Value "Deleting $Email" -force
try
{
$userDeleteRaw = @{
disableWithoutDelete='false'
eMail=$Email
}
#Debug
$userDeleteRawJSON = $userDeleteRaw | ConvertTo-JSON
Add-Content -Path "LogBuyDebug.log" -Value $userDeleteRawJSON -force
$userDelete = @()
$userDelete += @($userDeleteRaw)
$userDeleteBody = [System.Text.UTF8Encoding]::GetEncoding('UTF-8').GetBytes((ConvertTo-Json $userDelete))
$inputParameters = "?customerId=$($script:CustomerId)&countryId=0&defaultPortalId=0"
$userDeleteUrl = "$($script:BaseUrl)/users/deleteUsers$($inputParameters)"
$result = Invoke-RestMethod -Method 'Post' -Uri $userDeleteUrl -Body $userDeleteBody -Headers $script:headers
#Debug
$resultJson = $result | ConvertTo-JSON
Add-Content -Path "LogBuyDebug.log" -Value $resultJson -force
if($result.result.Errors -gt 0) {
if($result.result.messages -like "* Error: Email findes ikke på kunden") {
return $result
}
else {
throw $result.result.messages
}
}
else {
Return $result
}
}
catch
{
throw
}
}
]]>
</CustomCommand>
<CustomCommand Name="New-LogBuyUser">
<![CDATA[
[CmdletBinding()]
[OutputType([String])]
param
(
[parameter(Mandatory = $true)]
[string]$Email,
[parameter(Mandatory = $true)]
[string]$FirstName,
[parameter(Mandatory = $true)]
[string]$Surname,
[parameter(Mandatory = $true)]
[string]$SalaryNumber,
[int16]$Gender = 0
# Name Value
# Male 1
# Female 2
# Other 3
# Unknown 0
)
process
{
try
{
$userAddRaw = @{
email=$Email
firstName=$FirstName
surname=$Surname
salaryNumber=$SalaryNumber
gender=$Gender
}
# Debug
$userAddRawJson = $userAddRaw | ConvertTo-JSON
Add-Content -Path "LogBuyDebug.log" -Value $userAddRawJson -force
$userAdd = @()
$userAdd += @($userAddRaw)
$userAddBody = [System.Text.UTF8Encoding]::GetEncoding('UTF-8').GetBytes((ConvertTo-Json $userAdd))
$inputParameters = "?customerId=$($Script:CustomerId)&countryId=0&defaultPortalId=0"
$userAddUrl = "$($script:BaseUrl)/users/import$($inputParameters)"
$result = Invoke-RestMethod -Method 'Post' -Uri $userAddUrl -Body $userAddBody -Headers $script:headers
#Debug
$resultJson = $result | ConvertTo-JSON
Add-Content -Path "LogBuyDebug.log" -Value $resultJson -force
if($result.result.Errors -gt 0) {
if($result.result.errorDetails.Message -like "* already exists in current customer or in another country") {
Return $result
}
else {
throw $result.result.errorDetails.Message
}
}
else {
Return $result
}
}
catch
{
throw
}
}
]]>
</CustomCommand>
<CustomCommand Name="Test">
<![CDATA[
[CmdletBinding()]
[OutputType([String])]
param
(
)
Add-Content -Path "LogBuyDebug.log" -Value "Test" -force
]]>
</CustomCommand>
<CustomCommand Name="ConnectUtils">
<![CDATA[
param(
[parameter(Mandatory =$true, ValueFromPipelineByPropertyName =$true)]
[ValidateNotNullOrEmpty()]
[string]$AppURI ,
[parameter(Mandatory =$true, ValueFromPipelineByPropertyName =$true)]
[ValidateNotNullOrEmpty()]
[string]$AuthURI ,
[parameter(Mandatory =$true, ValueFromPipelineByPropertyName =$true)]
[ValidateNotNullOrEmpty()]
[string]$AppSecret ,
[parameter(Mandatory =$true, ValueFromPipelineByPropertyName =$true)]
[ValidateNotNullOrEmpty()]
[string]$CustomerId
)
#Debug
Add-Content -Path "LogBuyDebug.log" -Value "ConnectUtils Called" -Force
Add-Content -Path "LogBuyDebug.log" -Value "AppURI: $AppURI" -Force
Add-Content -Path "LogBuyDebug.log" -Value "CustomerId: $CustomerId" -Force
Add-Content -Path "LogBuyDebug.log" -Value "AuthURI: $AuthURI" -Force
Add-Content -Path "LogBuyDebug.log" -Value "AppSecret: $AppSecret" -Force
$script:baseUrl = $AppURI
$script:CustomerId = $CustomerId
$script:headers = Get-LogBuyAuthenticationHeaders -AuthUrl $AuthURI -CustomerId $CustomerId -AppKey $AppSecret
# Debug
Add-Content -Path "LogBuyDebug.log" -Value "Headers" -Force
$headersJSON = $script:Headers | ConvertTo-JSON
Add-Content -Path "LogBuyDebug.log" -Value $headersJSON -Force
]]>
</CustomCommand>
<CustomCommand Name="DisconnectUtils">
<![CDATA[
]]>
</CustomCommand>
</CustomCommands>
<!--======Predefined Commands================
-->
<PredefinedCommands>
</PredefinedCommands>
<!--======Environment Initialization================
-->
<EnvironmentInitialization>
<!--======Connect================
-->
<Connect>
<CommandSequence>
<Item Command="ConnectUtils" Order="0">
<SetParameter Param="AppURI" Source="ConnectionParameter" Value="AppURI" />
<SetParameter Param="AuthURI" Source="ConnectionParameter" Value="AuthURI" />
<SetParameter Param="AppSecret" Source="ConnectionParameter" Value="AppSecret" />
<SetParameter Param="CustomerId" Source="ConnectionParameter" Value="CustomerId" />
</Item>
</CommandSequence>
</Connect>
<!--======Disconnect================
-->
<Disconnect>
<CommandSequence>
<Item Command="DisconnectUtils" Order="0">
</Item>
</CommandSequence>
</Disconnect>
</EnvironmentInitialization>
</Initialization>
<!--======Classes Parameter================
-->
<Schema>
<Class Name="Person">
<!--======Properties================
-->
<Properties>
<Property Name="Email" DataType="String" IsUniqueKey="true" IsMandatory="true" IsMultivalue="false" IsDisplay="true" IsRevision="false" IsAutoFill="false">
<ModifiedBy>
<ModBy Command="New-LogBuyUser" />
</ModifiedBy>
<CommandMappings>
<Map ToCommand="New-LogBuyUser" Parameter="Email" />
<Map ToCommand="Remove-LogBuyUser" Parameter="Email" />
</CommandMappings>
<ReturnBindings>
<Bind CommandResultOf="Get-LogBuyUser" Path="Email" />
</ReturnBindings>
</Property>
<Property Name="FirstName" DataType="String" IsUniqueKey="false" IsMandatory="true" IsMultivalue="false" IsDisplay="false" IsRevision="false" IsAutoFill="false">
<ModifiedBy>
<ModBy Command="New-LogBuyUser" />
</ModifiedBy>
<CommandMappings>
<Map ToCommand="New-LogBuyUser" Parameter="FirstName" />
</CommandMappings>
<ReturnBindings>
<Bind CommandResultOf="Get-LogBuyUser" Path="FirstName" />
</ReturnBindings>
</Property>
<Property Name="Surname" DataType="String" IsUniqueKey="false" IsMandatory="true" IsMultivalue="false" IsDisplay="false" IsRevision="false" IsAutoFill="false">
<ModifiedBy>
<ModBy Command="New-LogBuyUser" />
</ModifiedBy>
<CommandMappings>
<Map ToCommand="New-LogBuyUser" Parameter="Surname" />
</CommandMappings>
<ReturnBindings>
<Bind CommandResultOf="Get-LogBuyUser" Path="Surname" />
</ReturnBindings>
</Property>
<Property Name="SalaryNumber" DataType="String" IsUniqueKey="false" IsMandatory="true" IsMultivalue="false" IsDisplay="false" IsRevision="false" IsAutoFill="false">
<ModifiedBy>
<ModBy Command="New-LogBuyUser" />
</ModifiedBy>
<CommandMappings>
<Map ToCommand="New-LogBuyUser" Parameter="SalaryNumber" />
</CommandMappings>
<ReturnBindings>
<Bind CommandResultOf="Get-LogBuyUser" Path="SalaryNumber" />
</ReturnBindings>
</Property>
<Property Name="Gender" DataType="Int" IsUniqueKey="false" IsMandatory="false" IsMultivalue="false" IsDisplay="false" IsRevision="false" IsAutoFill="false">
<ModifiedBy>
<ModBy Command="New-LogBuyUser" />
</ModifiedBy>
<CommandMappings>
<Map ToCommand="New-LogBuyUser" Parameter="Gender" />
</CommandMappings>
<ReturnBindings>
<Bind CommandResultOf="Get-LogBuyUser" Path="Gender" />
</ReturnBindings>
</Property>
</Properties>
<!--======ReadConfiguration================
-->
<ReadConfiguration>
<ListingCommand Command="Get-LogBuyUsers" />
<CommandSequence>
<Item Command="Get-LogBuyUser" Order="1" />
</CommandSequence>
</ReadConfiguration>
<!--======Method Configuration================
-->
<MethodConfiguration>
<Method Name="Insert">
<CommandSequence>
<Item Command="New-LogBuyUser" Order="1" />
</CommandSequence>
</Method>
<Method Name="Delete">
<CommandSequence>
<Item Command="Remove-LogBuyUser" Order="1" />
</CommandSequence>
</Method>
</MethodConfiguration>
</Class>
</Schema>
</PowershellConnectorDefinition>