Basic Web Request Troubleshooting


#1

I’m struggling a bit troubleshooting the “Web Request” function in webCoRE. Specifically, I’m attempting to make a simple PUT submission to the Zoneminder API I have running on a local workstation. The curl equivalent is curl -XPUT http:servername/zm/api/monitors/1.json -d "Monitor[Enabled]=1". I’m setting a variable to capture the data payload, and more piston looks like the following:

Any thoughts? Even better - what’s the best way to troubleshot Web Requests? Tracing and Logging seem to provide little.

-Jeff


Need your feedback on a new key-value piston input type in webCoRE
Ability to specify FORM / Value pairs in Web Requests
Working with todoist API in Webcore
#2

It doesn’t seem to be possible currently. The variable name is actually used as the FORM parameter name, so in your case the variable name would be Monitor[Enabled] and the value of that variable would be 1. However, Monitor[Enabled] as a variable name is converted to Monitor_Enabled_ to avoid syntax conflicts.

You may get some mileage out of IFTTT. If you sign up and connect your account to WebCoRE you can create a Webhook in IFTTT that takes this value and in turn calls the Zoneminder API with the correct formatting. You can pass along the monitor id and enabled status as two separate parameters then use them in the request. Let me know if you’d like more help with that.

This notation is quite common, I wonder if alternative methods have been considered for constructing these requests.


XML Web request
LaMetric Time Notifications
Debugging Slack Web Requests
#3

Ugh. That kind of stinks. Is there any way to just pass a raw string rather than variables and FORM parameters? I’m not optimistic.

I believe I could probably hack this together with an IFTTT integration. It just seems so - unnecessary.

Thanks for the insight!


#4

I agree, it doesn’t seem like you can do it directly in WebCoRE but I would love to be corrected on that. IFTTT is a bit limited so that may not be a solution in all cases but it should work here.


#5

I might need your assistance on setting up that IFTT/Webhook integration. I thought it was going to be straight-forward, but alas, nothing is ever easy.

I’d show you my applet definition - but it doesn’t appear that IFTTT allows that very easily.


#6

No problem, hopefully I can help! I would do the following:

  1. Create a new “Webhooks” applet with a name like “zoneminder_monitor_put”
  2. Add a “Webhooks” action to that
  3. Complete the form in a way that makes sense to you. To make this reusable, I would use the {{Value1}} parameter in IFTTT to specify the monitor id (which I assume is the 1 in 1.json), then the {{Value2}} parameter for the request body.
  4. Be sure to choose the Content Type application/x-www-form-urlencoded

You’ll end up with something like this:

Next, follow the instructions in the webCoRE dashboard settings screen to connect to your IFTTT account. If you followed the steps above you can use Send an IFTTT Maker Event in your pistons with the following values:

  • Event name: zoneminder_monitor_put
  • Value 1: 1
  • Value 2: Monitor[Enabled]=1

Of course you can also use variables from your piston like Monitor[Enabled]={monitorEnabled} and send other API parameters as well. I hope that helps!

You mentioned this is running locally; you will need to use a public IP address or hostname in order for IFTTT to connect since this request will not be initiated from your local network.


#7

Worked like a champ. Perfect workaround. Thanks for all your help. I now have fairly good integration between ZoneMinder cameras and SmartThings/webCoRE.


#8

You’re welcome! For others that might see this there are some important limitations:

  • IFTTT does not allow you to specify request headers (sometimes needed for auth tokens); webCoRE’s web request functionality does
  • IFTTT only allows passing in 3 “ingredients” so you may need to get creative or like the example above create the request body in webCoRE
  • webCoRE does not have a function to encode or decode URL components (e.g. if you’re dealing with more complex form parameter values) but if you need to encode a parameter value IFTTT can do it by wrapping it with <<<>>> like <<<{{Value1}}>>>

#9

If I might sneak a request in here…you mentioned earlier, and I also will note, that the identifier[attribute]=value nomenclature is pretty standard. We need a way to handle "[’ and “]” without automatic reformatting in webCore variables or at least a way to have a little more granular control of values passed in Web Requests. However, without having webCoRE as it is today, I wouldn’t even be in a position to even consider what I’m current achieving. Kudos to the team!


#10

Absolutely, though I would rather see the ability to specify name and value pairs each as values, expressions, etc. on the web request rather than allowing those characters in variables. It would be easier to work with strange keys like this if you could just type them in at the web request screen, and webCoRE could still do the url encoding behind the scenes. There are a good number of features like this that rely on creating variables with a specific name (e.g. arguments when executing a piston)

Would you please post a feature request in the Meta/Feature Requests category?


#11

Have you tried changing the variable type to ‘string’ to avoid the reformatting issue?


#12

Unfortunately, it’s not quite that simple. The Web Request function uses the webCoRE variable name / value pair as the FORM data when making a request. So if you want to pass the FORM variable “Variable” with value “true” in a Web Request, you need to have a webCoRE variable named “Variable” with the value “true” as an argument in the Web Request. However, if you need to use a FORM variable with characters that webCoRE doesn’t like, you have a problem. We managed an OK workaround, but I will submit a feature request nonetheless.


#13

Im not sure if I should create a new topic or not, I guess I’ll try this for now…

I am attempting a FORM POST web request and its sending back a 400 in the $httpStatusCode. I read somewhere that any response from the request will be in $response, but when I log it to console all that returns is “[ : ]”. is this a null value?


#14

I believe that is an empty list. We might be able to help, just create a new topic with a bit of background info on the service to which you’re trying to connect.