API Endpoint Format and Filtering

Product: PowerShell Universal
Version: 2.2.1

Hi @adam I have started to look at API’s but really getting stuck on the formatting to allow the endpoint to filter results.

If i create a simple Endpoint called GetExample as below it has some strange behaviour. I am using PSUCache to store the data from another process, but in this example i have the psobject in the endpoint

First test, return the entire psobject, this works.


New-PSUEndpoint -Url "/api/v1/GetExample" -Description "Example" -Method "Get" -Endpoint {
    # Setting PSUCache with dummy data
    $ArrayData = [psobject]@{
        id = "1"
    } | ConvertTo-Json
    Set-PSUCache -Key "ArrayData" -Value $ArrayData
    $GetArray = Get-PSUCache -Key "ArrayData" 
    $GetArray
}

Result:


Next trying to only return the value for the id property does not return ‘1’ as expected

New-PSUEndpoint -Url "/api/v1/GetExample" -Description "Example" -Method "Get" -Endpoint {
    # Setting PSUCache with dummy data
    $ArrayData = [psobject]@{
        id = "1"
    } | ConvertTo-Json
    Set-PSUCache -Key "ArrayData" -Value $ArrayData
    $GetArray = Get-PSUCache -Key "ArrayData" 
    $GetArray.id
}

Result:

What is strange is the object works the opposite arround if i use | ConvertFrom-Json after the Get-PSUCache statement:

New-PSUEndpoint -Url "/api/v1/GetExample" -Description "Example" -Method "Get" -Endpoint {
    # Setting PSUCache with dummy data
    $ArrayData = [psobject]@{
        id = "1"
    } | ConvertTo-Json
    Set-PSUCache -Key "ArrayData" -Value $ArrayData
    $GetArray = Get-PSUCache -Key "ArrayData" | ConvertFrom-Json
    $GetArray
}

Result:

New-PSUEndpoint -Url "/api/v1/GetExample" -Description "Example" -Method "Get" -Endpoint {
    # Setting PSUCache with dummy data
    $ArrayData = [psobject]@{
        id = "1"
    } | ConvertTo-Json
    Set-PSUCache -Key "ArrayData" -Value $ArrayData
    $GetArray = Get-PSUCache -Key "ArrayData" | ConvertFrom-Json
    $GetArray.id
}

Result:

The idea here is to drag an object from PSUCache, and filter on it with ID to return a single object. Whatever i do i cant seem to get this simple concept to work!

Any thoughts? im sure its just one of those annoying object issues!

EDIT::

This also has the same behaviour in the GUI when using Integrated scripts and API, although you can actually see the blank object:
image