#Param must be the first executable line
Param(
[string] $ContactComment = "Inital Entry",
[string] $SystemLoginID = "12345",
[string] $IsActive = "0",
[string] $Name = "HALL, NICHOLAS A",
[string] $DefaultTemplateID = "T1201",
[string] $AppliedTemplateID = "T1201",
[string] $LinkedTemplateID1 = "T1201",
[string] $LinkedTemplateID2 = "T2100303",
[string] $UserSubtemplateIDs1 = "T063",
[string] $UserSubtemplateIDs2 = "ST5083",
[string] $CustomUserDictionaries = "\\\\epic-server\\User_Dictionaries\\12345dictionary.tlx"
)
#Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host
#https://vm9008.info.sys/Interconnect-REL-EDI/DeveloperView/Main.aspx?clientid=1
$Request = '{"LinkedTemplatesConfig":{"DefaultTemplateID":{"ID":"' + $DefaultTemplateID + '","Type":"external"},"AppliedTemplateID":{"ID":"' + "$AppliedTemplateID" + '","Type":"external"},"AvailableLinkableTemplates":[{"StartDate":"","EndDate":"","LoginTypes":[],"LinkedTemplateID":{"ID":"' + "$LinkedTemplateID1" + '","Type":"external"}},{"StartDate":"","EndDate":"","LoginTypes":[],"LinkedTemplateID":{"ID":"' + "$LinkedTemplateID2" + '","Type":"external"}}]},"UserSubtemplateIDs":[{"Index":"1","Identifier":{"ID":"' + "$UserSubtemplateIDs1" + '","Type":"external"}},{"Index":"2","Identifier":{"ID":"' + "$UserSubtemplateIDs2" + '","Type":"external"}}],"CustomUserDictionaries":[{"Index":"1","Value":"' + $CustomUserDictionaries + '"}],"LinkedProviderID":{"ID":"","Type":""},"IdentityIDs":[],"ExternalIdentifiers":[{"Identifier":"e12345","IdentifierType":"EMC Mckesson Document Imaging","IsActive":"true"}]}'
try
{
$RestResults = Invoke-RestMethod -Method Put $url -contentType "application/json" -Body $Request
foreach($id in $RestResults.UserIDs)
{
Write-Host $id.ID - $id.Type
}
if ($RestResults.UserIDs.Count -eq 4)
{
Write-Host "SUCCESS!"
}
$RestResults.Messages
}
catch
{
if ($_.exception.Response.StatusCode -eq "BadRequest")
{
#$_.exception.Response.StatusDescription
if ($_.exception.Response.StatusDescription -match '^.*System login ID must be unique\.')
{
Write-Host "Already Exist!"
}
else
{
Write-Host "BadRequest: " $_.exception.Response.StatusDescription
}
}
else
{
$_.Exception | gm
$_.Exception | Select-Object -Property *
$_.exception.Response.StatusCode
}
#$_.exception.message
#$_.exception.InnerException
#$_.Exception.ItemName
}