API authorization help

Product: PowerShell Universal
Version: 2.1.2

I have an API that will return the expected results when not set to require authorization.

When I require authentication and use the cookie method of calling the API I get no data returned

When I create a token I get no data returned as well.

Found the logs showing it seems to run the API

But I’m not getting the expected data. I tried logging inside of the API call by putting data into a text file at certain area’s, but nothing logs.

Can you try to set the error action to stop on your endpoint? I wonder if it’s eating an error that might be preventing your endpoint from running.

In Settings \ Configurations \ endpoints.ps1, you can set the error action on New-PSUEndpoint.

New-PSUEndpoint -Url "/object" -Method "POST" -Endpoint {
throw "Hey"
} -Authentication -ErrorAction Stop

Adding in the erroraction gave me this

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

and this is in the logs

Are you invoking this in PowerShell 5.1? It wont give you a good error message like 7.1 will. Try something like this:

  try {
 Invoke-RestMethod http://localhost:5000/percent
    }
    catch {
        $streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
        $ErrResp = $streamReader.ReadToEnd() 
        $streamReader.Close()
    }

    $ErrResp

Ahh, that gave me a good error

A parameter cannot be found that matches parameter name 'identity'.
at <ScriptBlock>, <No file>: line 1

I looked through my endpoint script and don’t have anything with the Identity parameter. I do have another Invoke-RestMethod inside of that endpoint though calling our password manager.

When authenticating to an API, does it pass credentials thought? So I auth to use the API, then inside that endpoint it reaches out to another service, what creds does it use for that? Whatever PU is running as?