[SOLVED] Make a POST request on a local network IP

variables

#1

1) Give a description of the problem
(PUT YOUR INFO HERE)
Hello,
I’m trying to create a simple piston which makes a POST request on a local network IP ( a Bose soundbar) using the API provided by Bose Devs.
In this Moment I’m kinda newbie in this domain but I will try to learn.Untill then, please help me out!

2) What is the expected behaviour?
(PUT YOUR INFO HERE)
I would like that my piston would execute the desired command using the make a POST request.

3) What is happening/not happening?
(PUT YOUR INFO HERE)

After I run the piston…nothing happens.I think I did not made the correct piston-variable-attributes.
When I use the Command Prompt curl, the Post request it’s fully functional, but when I put the same “link” in my piston it does not work.

The IP Address of my Bose SoundTouch 300 is 192.168.100.22:8090 and the command that it’s working using the Curl software is:

curl -X POST -H “application/xml;charset=utf- bose_tv_source: curl -X POST -H “application/xml;charset=utf-8” -d ‘<?xml version=“1.0” ?><ContentItem source=“PRODUCT” sourceAccount=“TV”></ContentItem>” http://<soundtouch ip address>:8090/select8’ -d ‘<?xml version=“1.0” ?><ContentItem source=“PRODUCT” sourceAccount=“TV”></ContentItem>’ http://192.168.100.22:8090/select

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

+1ms ╔Received event [Acăsică].time = 1573134910347 with a delay of -1276ms
+75ms ║RunTime Analysis CS > 17ms > PS > 43ms > PE > 15ms > CE
+77ms ║Runtime (37306 bytes) successfully initialized in 43ms (v0.3.110.20191009) (75ms)
+79ms ║╔Execution stage started
+80ms ║╚Execution stage complete. (1ms)
+81ms ╚Event processed successfully (81ms)

Thank


#2

I am new to POST requests with webcore so I am not the expert here. But my POST requests look like this :

I am presuming that you are defining your “variable” the same value used in your Curl statement.


#3

Not really an area I’ve been involved in much, and I’m rather hoping the curl command you quoted has got corrupted in same way, but I think you are right in thinking you need some work on your HTTP request. At the moment your request has an empty body (the variable doesn’t have any content) and claims to by JSON data when it is clearly XML. So to start with you could try:

REQUEST BODY TYPE: Value > CUSTOM
REQUEST BODY: Value > The contents of your -d argument to curl without the ‘’ around it.
REQUEST CONTENT-TYPE: Value > application/xml

The alternative for the request body is to initialise the variable you’ve already created with the same content and use the variable. Whatever is most convenient for you really.

I’ll now defer to those with more experience in this area, though.


#4

Hi,

Yes, the constant variable is:

‘‘

which the the actual API command that I should run on “soundbarIP:8090/select URL

Now my piston looks like this:

For testing purposes I’ve posted the variable on to requestcatcher.com and it s receiving:

I guess it’s ok…

Now my next step would be (if I understood from other posts) to replace the URL with my “publicIP:portforwared” to the local IP address of my Device.
My problem is now that I don’t know how to make this right, because I have to do something like this:

10.x.x.x:port -> 192.168.100.22:8090/select
It has to be /select because otherwise the command will not work.I think I can manage to make the normal port forwarding from my ISP router webpage, but I don’t know how to do the “/select” part.

Any thoughts?
Thanks


#5

So, I am now getting in over my head, but I just have to use my public IP address and my forwarded port to reach my device… publicIP:portforwarded…just as you said. I did not have to use the local IP address of my device… your 192.168.100.22. Not sure how to do the “/select” part. I barely understand the JSON that I am using. Sorry, but someone with more expertise will have to chime in here for that. :slight_smile:


#6

Thank you for you effort! I am also over my head here…
Maybe an expert will step in :grin:


#7

@ipaterson helped me greatly. Maybe he can provide guidance here…


#8

I think your original post had an accidental paste into the middle of the curl command and it should say:

curl -X POST -H "application/xml;charset=utf-8" -d '<?xml version="1.0" ?><ContentItem source="PRODUCT" sourceAccount="TV"></ContentItem>' http://192.168.100.22:8090/select

I now realise that you already had variable defined correctly - it just doesn’t show up in webCoRE.

You are not actually using any JSON. You are sending XML and your requestcatcher response is looking good to me.

Where you have lost me is in your discussion of public IP and port forwarding. Your working curl command uses the URL http://192.168.100.22:8090/select so I don’t understand why you wouldn’t use that as the URL. webCoRE is going to assume that is a local IP address and will tell your SmartThings hub to handle it. So as long as your hub and your SoundTouch are on the same network it should work.


#9

Oh,
I did not know that WebCore can do that…I will give it a try and get back to you.

Regarding the variable discussion the answer is yes, I’ve already put the info with contentItem in the variable.

I will get back to you guys,
Vlad


#10

So I was under the impression that I had to use my public IP address. I just tested with my local IP:portforward and IT WORKED! Thanks @orangebucket
Now I need to edit about 20 pistons to change from my public IP to my local device IP.


#11

Unfortunately the device does not responds to my command.Either it’s something wrong with the piston or with the API command …
Here are the logs:

Logs

11/8/2019, 4:17:06 PM +58ms
+0ms ╔Received event [Acăsică].time = 1573222627542 with a delay of -1485ms
+90ms ║RunTime Analysis CS > 27ms > PS > 42ms > PE > 22ms > CE
+93ms ║Runtime (37295 bytes) successfully initialized in 42ms (v0.3.110.20191009) (92ms)
+94ms ║╔Execution stage started
+95ms ║╚Execution stage complete. (2ms)
+96ms ╚Event processed successfully (97ms)
11/8/2019, 4:16:48 PM +110ms
+0ms ╔Received event [Acăsică].wc_async_reply = httpRequest with a delay of 0ms
+86ms ║RunTime Analysis CS > 28ms > PS > 36ms > PE > 22ms > CE
+89ms ║Runtime (37299 bytes) successfully initialized in 36ms (v0.3.110.20191009) (87ms)
+89ms ║╔Execution stage started
+96ms ║╚Execution stage complete. (6ms)
+97ms ╚Event processed successfully (96ms)
11/8/2019, 4:16:47 PM +412ms
+0ms ╔Received event [Acăsică].test = 1573222607411 with a delay of 0ms
+102ms ║RunTime Analysis CS > 23ms > PS > 49ms > PE > 31ms > CE
+105ms ║Runtime (37292 bytes) successfully initialized in 49ms (v0.3.110.20191009) (104ms)
+106ms ║╔Execution stage started
+112ms ║║Cancelling statement #1’s schedules…
+124ms ║║Sending internal web request to: 192.168.100.22/select
+127ms ║║Executed virtual command httpRequest (4ms)
+129ms ║║Requesting a wake up for Fri, Nov 8 2019 @ 4:17:07 PM EET (in 20.0s)
+148ms ║╚Execution stage complete. (42ms)
+156ms ║Setting up scheduled job for Fri, Nov 8 2019 @ 4:17:07 PM EET (in


#12

It certainly looks like it sent a request and received a reply so the next step is probably to see what it thinks it has been up to. You could add a couple of ‘log to console’ actions after the request, one for the variable $httpStatusCode (so your usual 200, 400, 403 etc) and one for the variable $response (the content of any response).


#13

Possibly relevant, there is a fix waiting for the next release to avoid an exception when the server responds with a 204 (No Content) status code. Check your account.smartthings.com > Live Logging to see if any exceptions are being logged.

Not sure why the device would not be responding though, that’s strange. Does your request body begin with <?xml version="1.0" ?> like @orangebucket showed in the curl above?

You’re right, there were some serious problems with local requests in the past but this year’s updates fixed them up. ST does not support everything in the same way, but in general local requests will work.


#14

Hi all!

I want to start by saying a big thank you for all of you!
My piston it’s working now!

As @ipaterson said, that sentence was missing from my body.
Added that and now it’s working just fine!


#15

@vsterian you can’t give yourself a Solution Check Mark, from reading this thread, you should withdraw it and give it to @orangebucket out of courtesy.


#16

Sorry, I did not know that:D
I thought you tick the solution, when the topic it’s solved.
The “solution tick” went to @orangebucket !

Sorry again :smiley: