functions/New-BBTerm.ps1


#Does not create a new one if one exists. This is how the API Works.
function New-BBTerm
{
    [CmdletBinding(SupportsShouldProcess)]
    [Alias()]
    Param
    (
        [parameter(ValueFromPipelineByPropertyName)][string]$externalId,
        [parameter(ValueFromPipelineByPropertyName)][string]$dataSourceId = "",
        [parameter(ValueFromPipelineByPropertyName)][string]$name = "",
        [parameter(ValueFromPipelineByPropertyName)][string]$description = "",
        [parameter(ValueFromPipelineByPropertyName)]$availability = "",
        [string]$Environment = 'Production'
    )

    Begin
    {

    }
    Process
    {
        $Body = @{}
        if($externalId){$Body.Add('externalId', $externalId)}
        if($dataSourceId){$Body.Add('dataSourceId', $dataSourceId)}
        if($name){$Body.Add('name', $name)}
        if($description){$Body.Add('description', $description)}
        if($availability){$Body.Add('availability', $availability)}

        Invoke-BBRestMethod -API "/learn/api/public/v1/terms"`
            -Method Post `
            -ContentType application/json `
            -Body $Body `
            -Environment $Environment
    }
    End
    {
    }
}