I’m toying around the UA in my lab to verify and understand being able to make the API calls to start scripts. I’ve got my auth and calling the script working properly, but I’ve been banging my head against a wall figuring out the proper structure for passing the arguement parameters into the script.
Right now I’m working with just Invoke-RestMethod and formatting as application/json content type.
Any input or direction would be appreciated, APIs never seem to be my strongsuit.
I’d be very much interested as well to get some hints about how to pass params to a script, I’ve been trying it all day yesterday and didn’t had a chance to make it work with the post method /api/v1/script/{id}.
i do that all day long xD
so for example, if you have a route like that : /api/v1/script/{1}
the ud code should look like this :
$yourRoute = New-UDEndpoint -Url "/v1/script/:VarName" -Method GET -Endpoint {
param($VarName)
# do something with $varname
# return some json
}
For Post/delete routes
$yourRoute = New-UDEndpoint -Url "/v1/script/:VarName" -Method POST -Endpoint {
param($VarName,$Body)
# do something with $varname
# $body contains some json, so you can convertit to work with a psobject !
}
Well, I know how to do it using UDashboard the question here is about UniversalAutomation and how to pass params to scripts that are triggered by the POST method predefined on the UAServer corresponding to /api/v1/script/{1} as explained on the swagger UI.
I just tried this myself and it’s way harder than it needs to be. I’m going to work on simplifying this API so you can call it similar to UD.
The problem is that the body of the request needs to be a very specific format. UA stores all the pipeline output and arguments as CliXml. Right now, it’s expecting a payload that looks like this.
Btw, I’m as well struggling with feeding params to scripts using Invoke-UAScript, can anyone help me with this ? I’d be very grateful.
Thanks a lot in advance !
Edit: I’ve been able to feed script params using the Set-UAJobFeedback but, in this situation, my script have 2 parameters and the Get-UAJobFeedback cmdlets only returns the first params of the script. If I try to start the script from the UADashboard the modal ask me for 2 params, but if I start the script, using Invoke-UAScript, the script is in Waiting Feedback states and same behaviour, it only asks for one params which, in this case, is the first one.
Any Ideas ?
Edit 2: Found out that you can splat script’s params and pass them to the Invoke-UAScript, tho it seems like the cmdlet automatically reformat the variable adding prefix and suffix and the variable looks like that:
It now contains UA and the Invoke-UAScript cmdlet should be fixed. We will be publishing the UA cmdlets to the Gallery soon but they are currently just in the PSU zip.
Pinging you back about invoking scripts from the Management API with parameters, is there any simplified solution available with a POST payload ?
I’ve been trying the 1.5.9 and the -UseDefaultCredentials use very well but still trying to find a simple way to invoke scripts, with params, from the API.
I’ve been starting scripts with parameters for a while now. Here’s an example with splatting:
(The script “some_script_in_automation_section.ps1” accepts 3 parameters: customer, email and user. I get the values from a user than goes through a stepper)