Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-FreshServiceSolutionFolder issues #20

Open
lucafabbri365 opened this issue Apr 29, 2024 · 1 comment
Open

Get-FreshServiceSolutionFolder issues #20

lucafabbri365 opened this issue Apr 29, 2024 · 1 comment

Comments

@lucafabbri365
Copy link

lucafabbri365 commented Apr 29, 2024

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.

@lucafabbri365
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant