Skip to content

Get-FreshServiceSolutionFolder issues #20

Description

@lukedaemon

Hello,
the Get-FreshServiceSolutionFolder cmdlet doesn't work when multiple results are returning (FreshservicePS module version 0.1.6).

If I run this cmdlet to retrieve the list of a Folder with Id 66175 belonging to Category with Id 187:

Get-FreshServiceSolutionFolder -Id 66175 -category_id 187

...this is the result:

description         :
id                  : 66175
created_at          : 2/20/2023 3:32:11 PM
updated_at          : 8/10/2023 7:52:34 AM
name                : News
category_id         : 187
position            : 11
visibility          : 6
approval_settings   :
workspace_id        : 2
default_folder      : False
parent_id           :
has_subfolders      : False
requester_group_ids : {163}
manage_by_group_ids : {}

But if I run this cmdlet to retrieve the list of all Folders belonging to Category Id 187:

Get-FreshServiceSolutionFolder -category_id 187

...I have no results.

I analyzed the Get-FreshServiceSolutionFolder.ps1 script included in FreshservicePS module:

$results = do {

    $params = @{
        Uri         = $uri
        Method      = 'GET'
        ErrorAction = 'Stop'
    }

    $result = Invoke-FreshworksRestMethod @params
    if ($result.Content) {
        $content = $result.Content |
                        ConvertFrom-Json

        #API returns singluar or plural property based on the number of records, parse to get property returned.
        $objProperty = $content[0].PSObject.Properties.Name
        Write-Verbose -Message ("Returning {0} property with count {1}" -f $objProperty, $content."$($objProperty)".Count)
        $content."$($objProperty)"
    }

    if ($result.Headers.Link) {
        $uri = [regex]::Matches($result.Headers.Link,'<(?<Uri>.*)>')[0].Groups['Uri'].Value
    }

}
until (!$result.Headers.Link)

When there is one result the $content[0].PSObjects.Properties.Name returns one property folder; but when there are multiple results there are two properties returned folders and meta ($objProperty is equal to System.Object[]). So I suppose the problem is related to how the (multiple) results are handled by the function.

I don't exclude this behavior could affect all other Get-Freshservice* cmdlets.

Activity

  1. lukedaemon commented on May 2, 2024

    @lukedaemon
    Author

    Hello,
    I found a workaround...

    • FROM: $objProperty = $content[0].PSObject.Properties.Name
    • TO: $objProperty = $content[0].PSObject.Properties.Name | Where-Object {$_ -like "folder*"}

    Bye,
    Luca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions