Is is possible to call a Powershell script from the REST API
Is is possible to call a Powershell script from the REST API
Hi,
I have tried many ways of calling a PowerShell script from the REST interface, but I cannot seem to get it right.
Is this possible and if so, what is the syntax?
Based on the help in http://www.opensourceautomation.com/wik ... title=REST and http://localhost:8732/api/help,
I would expect the below to work, but it returns a"True", but I don't see anything happening in OSA.
http://localhost:8732/api/object/PowerS ... m1=SayTime
Does anyone know if this is possible? I can call Pattern Matches fine, but I don't feel that this is the correct place to be calling these scripts.
Any help would be appreciated. If I have missed something similar in the forum, please direct me to to it
Andre
I have tried many ways of calling a PowerShell script from the REST interface, but I cannot seem to get it right.
Is this possible and if so, what is the syntax?
Based on the help in http://www.opensourceautomation.com/wik ... title=REST and http://localhost:8732/api/help,
I would expect the below to work, but it returns a"True", but I don't see anything happening in OSA.
http://localhost:8732/api/object/PowerS ... m1=SayTime
Does anyone know if this is possible? I can call Pattern Matches fine, but I don't feel that this is the correct place to be calling these scripts.
Any help would be appreciated. If I have missed something similar in the forum, please direct me to to it
Andre
Re: Is is possible to call a Powershell script from the REST
I agree that you should be able to directly call a script but that's not how it's currently set up. We've talked about adding this feature but it's not done yet.
Currently you have to create a pattern that points to the script and also a "pattern match" that points to the pattern.
Then use http://yourosaserver:8732/api/namedscript/{your pattern match name}
Currently you have to create a pattern that points to the script and also a "pattern match" that points to the pattern.
Then use http://yourosaserver:8732/api/namedscript/{your pattern match name}
Re: Is is possible to call a Powershell script from the REST
Well, in looking again at your REST command I'm not sure why it does not work. "SayTime" is the name of your script right?
Can you run the same PS script from the OSA Objects web page?
Does anything show up in the OSA logs?
Can you run the same PS script from the OSA Objects web page?
Does anything show up in the OSA logs?
Re: Is is possible to call a Powershell script from the REST
Pattern Matches in a way are supposed to be Friendly names for scripts that allows for many ways to call them. I think just another area were more work is needed to make them tied together right and for it to be more obvious. The goal of openness complicates things, so in trying to make the patterns more useful than just script alias, it broke using it as script alias to a degree.
I think the intended solution here was new scripts would automatically generate the patterns to call them... If this was done, there would not be a need for two separate calls... Calling a pattern should be much preferable to calling a script name directly, I think it just needs to automate a little of the work that makes it happen on the backend.
Vaughn
I think the intended solution here was new scripts would automatically generate the patterns to call them... If this was done, there would not be a need for two separate calls... Calling a pattern should be much preferable to calling a script name directly, I think it just needs to automate a little of the work that makes it happen on the backend.
Vaughn
Re: Is is possible to call a Powershell script from the REST
Hi Andre,
You will always get true returned from that Rest method your calling, however if the method isn't added to the queue for processing you see a message in the log. which will contain "API - MethodQueueAdd error". Are there any logs from the Powershell plugin? either containing "running script:" or "Error Processing Command"?
You will always get true returned from that Rest method your calling, however if the method isn't added to the queue for processing you see a message in the log. which will contain "API - MethodQueueAdd error". Are there any logs from the Powershell plugin? either containing "running script:" or "Error Processing Command"?
Re: Is is possible to call a Powershell script from the REST
I seem to have missed your second post Automate, sorry for not replying sooner.
I have just relooked at this and find the calling PS scripts from the REST interface is now working perfectly, with my original syntax.
It must has been a "can't see the forest for the trees" type of problem.
Thanks for the help.
In case anyone else needs it, the cURL syntax to call a Script from the REST interface is:-
and to call from a Python script
I have just relooked at this and find the calling PS scripts from the REST interface is now working perfectly, with my original syntax.
It must has been a "can't see the forest for the trees" type of problem.

Thanks for the help.
In case anyone else needs it, the cURL syntax to call a Script from the REST interface is:-
Code: Select all
curl --data -h "http://{IPAddressofOSA}:8732/api/object/PowerShell/Run%20Script?param1={scriptname}¶m2={parameter}"
Code: Select all
#!/usr/bin/env python
import subprocess
proc = subprocess.Popen(["curl", "--data" ,'-H', "http://{IPAddressofOSA}:8732/api/object/PowerShell/Run%20Script?param1={scriptname}¶m2={parameter}"])