API not working for Forms in Pages

Product: PowerShell Universal
Version: 1.4.6

Ran into an issue when trying to use API. The API I have created isn’t being displayed under target. Here is a recording of the occurrence. https://www.screencast.com/t/96pfV7gPNn3P

Can you try setting your API to a POST rather than a GET?

1 Like

So i got better results I am no longer getting errors but the GUI is acting funning for editing forms. But I am not getting results returned to the page. Is there something i have to do on the API end to get the results to come back?

This is what I got for results, Can it return my results from the script somehow?

[{"Id":0,"Url":"/CDB","Description":null,"Method":"GET","ScriptBlock":"\r\n# Enter your script to process requests.\r\n$Fields = $Body | ConvertFrom-Json\r\n$task = $Fields.task\r\n\r\n\r\n#region Script\r\n\t#region Add Oracle Data Access DLL\r\n\t$source = 'http://devops-utils.iqms.com/DL/Oracle/Oracle.ManagedDataAccess.dll'\r\n\t$destination = 'c:\\temp\\Oracle.ManagedDataAccess.dll'\r\n\tif (!(Test-Path $destination))\r\n\t{\r\n\t\tWrite-Host \"Downloading Oracle.ManagedDataAccess file...This may take a minute\"\r\n\t\t(New-Object Net.WebClient).DownloadFile($source, $destination)\r\n\t}\r\n\t#endregion\r\n    #region Get-OraData Function\r\n    Function Get-OraData {\r\n    param($sql, $filter)\r\n\t#region Connection Parameters\r\n\t$OracleDLLPath = $destination\r\n\t$da = New-Object System.Data.DataTable\r\n\t$username = \"sys\"\r\n\t$password = \"iqora\"\r\n\t$datasource = \"(DESCRIPTION =\r\n\t\t\t\t(ADDRESS =\r\n\t\t\t\t(PROTOCOL = TCP)\r\n\t\t\t\t(HOST  = dw-oracleCDB.dsone.3ds.com)(PORT = 1521))\r\n\t\t\t\t(CONNECT_DATA = (SERVER = DEDICATED)\r\n\t\t\t\t(SERVICE_NAME = cdb)\r\n\t\t\t\t(FAILOVER_MODE = (TYPE = SELECT)\r\n\t\t\t\t(METHOD =  BASIC)\r\n\t\t\t\t(RETRIES = 180)\r\n\t\t\t\t(DELAY = 5))))\"\r\n\t#endregion    \r\n\t#region Connection String\r\n\t$connectionstring = 'User Id=' + $username + ';Password=' + $password + ';DBA Privilege=SYSDBA' + ';Data Source=' + $datasource\r\n\t#$connectionstring = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource\r\n\t\r\n    #endregion\r\n    try\r\n    {\r\n        Add-Type -Path $OracleDLLPath -ErrorAction Stop\r\n    }\r\n    catch\r\n    {\r\n        $error[0].Exception.GetBaseException().LoaderExceptions\r\n    }\r\n    $con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionstring)\r\n    $con.Open()\r\n    $cmd = $con.CreateCommand()\r\n    $cmd.CommandText = $sql\r\n\t$cmd.CommandTimeout = 3600 #Seconds\r\n\t$cmd.FetchSize = 10000000 #10MB\r\n\t$rdr = $cmd.ExecuteReader()\r\n\t$da.Load($rdr)\r\n\t$da\r\n\t$con.close()\r\n    }\r\n    #endregion\r\n\r\n\tswitch ($task)\r\n\t{\r\n\t\tView {\r\n        $sql = @(\"select Name,OPEN_MODE FROM v`$containers WHERE NAME NOT IN('CDB`$ROOT','PDB`$SEED')\")\r\n        $dt = Get-OraData $sql\r\n\t\t$Query = $dt | ? { $_.name -like \"*$trigram*\" }\r\n\t\t$Query\r\n\t\t\r\n        }\r\n    }\r\n#endregion\r\n\r\n","Authentication":false,"Role":null,"RegEx":false,"ErrorAction":1,"Tag":null}]

Try setting your result type to table.

My API returns a hashtable.

When I run it, it returns each property as a column in the table.

I will try do something simple and test first, then i know its my script

Ah, I think I know the problem and I think it’s a confusing part of the docs. I’ve actually updated them to address this: Endpoints - PowerShell Universal

You don’t need to call New-PSUEndpoint within your endpoint. It’s only necessary in endpoints.ps1. If you are doing all your editing in the admin console, you can just put your go in the editor.

So in the docs, it mentions this command:

New-PSUEndpoint -Url '/endpoint' -Method 'GET' -Endpoint {
   "Hello, world!"

But that’s just the result in endpoints.ps1. All you really need to do is put this in the editor.