I was trying to make a API to upload a CSV file, run a script and print back the job output. So far, so good… But all the time I was getting a 401 unauthorized, when I wanted to invoke the script and also I need 2x use the Connect-UAServer to get is working.
So how can I get the same results, without setting the token and the connect to server and use the authentication, that is used by the execution of “Invoke-RestMethod”?
If you’re on 2.5.5, you can actually simplify this and remove the use of app tokens. We added an -Integrated switch to some cmdlets to make executing jobs easier from APIs and dashboards.
If you return the pipeline output and not the host output, you can return it as JSON which will then be translated to PSCustomObjects by PS if you use Invoke-RestMethod.
It won’t necessarily look exactly the same in the command line since it won’t include type data and the custom formatting may not kick in but give it a shot and see how it goes.
This was working based on the subfolder, but I did enter the “-path” variable instead of the “-name” variable
So my conclusion is that when you use “get-uascript -name”
The “-name” paramater is working, based on the name in “scripts.ps1”, for subfolder items when using “$apptoken =” and “Connect-UAServer” inside the API request
If you use the new simplified version, with the “-integrated” it can’t resolve based on the “-name” variable from “scripts.ps1”, if you replace it with using the “-path” variable instead by using “Get-PSU -Name” it can resolve the script.
Another thing I saw in your new example, is that you replaced “Invoke-UAScript” with, “Invoke-PSUScript”
3.1. I did test it also with “Get-UAScript” & “Invoke-UASCript”, what is giving the same results as “Get-PSUScript” & “Invoke-PSUSCript”
3.2. So this means they are doing exactly the same?
I will get a cup of coffee, and will try to combine it with you’r first sugestions for recieving the Job output.
But only when I add a pipe " | ConvertTo-Json" add the end of my “Invoke-Restmethod” I get a JSON output
Now I get interested what’s inside the $Hostoutput, so when set
$Hostoutput
I get a intresting output
What set me on thinking, if my “write-host” for logging is the best way or is there another way log the script / job steps what can be retrieved as a correct Json output also?
To make it a little more clear what I want to know if it’s possible both output in Json
The “$Pipeline” in Json, what’s the information I also needed
And separated the script logging / steps output in Json?
Because the above image looks like some logging to, I checked all cmdlets from the docs, can’t find a command for logging, maybe there is?
And af the end get 2 json outputs
3.1. The data that’s imported
3…2. A log, what maybe can get requested with a parameter
3.3. What can make it very useful when I start creating a dashboard I have in mind, to see the data and a log and set them side by side, almost like PSU does
It’s just a idea what’s coming up, you don’t need to write the complete code for me but maybe you can bring me a little in the right direction. And I want to build as most as possible based on API command and Json output, because I will create some WHMCS modules that need to talk to the API. >> What must make it possible to in the end integrate all kind off services in WHMCS, if it’s talking API / Powershell, then you can intergrade it inside a module from like everything.