Hi there
I am trying to connect from powershell to my core.
Using curl on a standard command line works nice
I seem to not clearly understnad how to http-post to the core.
tried to use ‘invoke-webrequest’ and failed miserably
Are you trying to use curl from the power shell, or are you trying to use built-in power shell functions?
If you’re using curl, you can pass the -d parameter to tell curl to perform an HTTP post request. Take a look at the Spark.function() documentation to see an example of using curl for HTTP post requests (it’s at the bottom of the example code).
@Laurent, I know this question is a bit old but I was doing a search and had the same question, and just now I found how to make PS work with the Spark API.
Invoke-RestMethod -Uri 'https://api.spark.io/v1/devices/YOUR-DEVICE-ID/YOUR-FUNCTION?access_token=YOUR-TOKEN' -Method Post -Body 'args=180'
The output from from that command is
id : YOUR-DEVICE-ID
name : Test-Home-Desk
last_app :
connected : True
return_value : 0
This example is for a servo function to set the angle to 180 degrees, the Invoke-RestMethod applet will deserialze the JSON response and set them into objects, so if you do this
$Servo = Invoke-RestMethod -Uri 'https://api.spark.io/v1/devices/YOUR-DEVICE-ID/YOUR-FUNCTION?access_token=YOUR-TOKEN' -Method Post -Body 'args=180'
You’ll be able to query the response by simply doing this
$Servo.connected
True
or
$Servo.return_value
0
One thing to keep in mind, the applet is only available on Powershell 4.0, if you’re in Windows 8+ you already have it, if you’re on Windows 7 you can install the Powershell 4.0 Framework