Public/new-AllegisIDNsourceSchemaAttribute.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function new-AllegisIDNsourceSchemaAttribute ($orgName, $sourceid, $accessToken, $usage, $attribute){
    #if ($usage -eq $null){$usage='Create'}
    $source=get-AllegisIDNsourceAccounts -orgName $orgname -sourceid $sourceid -accessToken $accessToken -usage $usage
    if ($source.fields.where{$_.name -eq $attribute} -ne $null){return "$attribute already exists",$source.fields.where{$_.name -eq $attribute}}
    $header=get-AllegisIDNprivateHeader $accessToken
    $header+=@{'Content-Type'='application/json'}
    if ($source.count -gt 1){
        $source[$source.usage.IndexOf('Create')].fields+=[PSCustomObject]@{
            attributes=[PSCustomObject]@{}
            isRequired=$false
            name=$attribute
            transform=$null
            type='string'
        }
    }else{
        $source.fields+=[PSCustomObject]@{
            attributes=[PSCustomObject]@{}
            isRequired=$false
            name=$attribute
            transform=$null
            type='string'
        }
    }
    $privateuribase="https://$orgname.identitynow.com"
    if ($usage -eq $null){
        $url="$privateuribase/api/accountProfile/bulkUpdate/$sourceid"
    }else{
        $url="$privateuribase/api/accountProfile/update/$($sourceid)?usage=$usage"
    }
    $json=$source | ConvertTo-Json -Depth 100
    if ($json[0] -ne '['){$json="[$json]"}
    $response=Invoke-WebRequest -Uri $url -Method Post -UseBasicParsing -Headers $header -Body $json
    $sourceAccountProfile=$response.Content | ConvertFrom-Json
    return $sourceAccountProfile
}