Assistance with "Make web request" action


#1

1) Description of the problem
I’m attempting to use the “make web request” function to call my amcrest camera API, but they disabled basic auth, so I have to use digest auth (or pass my credentials in the form http://user:pass@ip/request… as shown in the piston screenshot below).

2) What I’m expecting
Is there a way to use digest auth while making a web request via webCoRE? Or to make the URL in the piston screenshot below work?

3) What is happening
I attempted to pass my credentials in the URL (which works fine in my browser), but although the web request completes, it does not do anything

So I’m assuming that I’ll have to use digest auth, but I can’t figure out how to do this from webCoRE

4) Snapshot

5) Logs (with user/pass redacted)

10/3/2017, 4:08:25 PM +571ms
+0ms	╔Received event [Home].execute = 70.121.154.244 with a delay of 162ms
+111ms	║RunTime Analysis CS > 12ms > PS > 79ms > PE > 21ms > CE
+120ms	║Runtime (37046 bytes) successfully initialized in 79ms (v0.2.0ec.20170927) (120ms)
+121ms	║╔Execution stage started
+124ms	║║Cancelling statement #1's schedules...
+129ms	║║Sending internal web request to: user:[email protected]/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0&arg4=0%20
+131ms	║║Executed virtual command httpRequest (3ms)
+132ms	║║Requesting a wake up for Tue, Oct 3 2017 @ 4:08:45 PM CDT (in 20.0s)
+135ms	║╚Execution stage complete. (15ms)
+136ms	║Setting up scheduled job for Tue, Oct 3 2017 @ 4:08:45 PM CDT (in 19.997s)
+150ms	╚Event processed successfully (151ms)

Also, is there a way to see the response of the http web request? I don’t see a response anywhere in the logs.


Creating and sending a JSON Object for POST HTTP Request
#2

Try:

IP/request…&user={USERNAME}&pw={PASSWORD}

The password works in two ways, either by means of Basic Auth http://user:pass@… or by means of query string http://…&user=…&pw=…

The first way with user:pass@ does not work in Chrome - it gets blocked. The latter one does.


#3

Also, instead of typing your credentials into the URL, you can extract the authentication header from your browser and paste that into the corresponding field in the webCoRE get request box.

  • Load the URL in the browser (without the credentials section) and enter your user/pass in the pop-up
  • Open the browser’s console (press F12) and go to the Network tab, then refresh the page
  • Select the request and look for the Request headers section, find the Authentication field - copy the value in there and paste it as a value into the authentication header field of the Make web request task in WebCoRE.

Most of the time you’ll see Authorization as “Basic blahblahblahMIMEencodedblahblahblah”


#7

Thanks for the quick response Robin!

But, I think I may have misstated my problem.

So the http://user:pass@ip/request form works perfectly in a browser (even in chrome surprisingly), but not in a “web request” action in webCoRE.

I cannot use basic auth because amcrest disabled basic auth and requires that all http calls be authenticated with digest auth. So I need to find a way to either have webCore accept the " http://user:pass@ip/request" form of the URL or do digest auth.

They do not appear to accept username and password as parameters. I’ve tried every combination of key (user=x/pass=y, username=x/password=y, user=x/password=y etc, but it does not look like they accept those as arguments)


#8

ahh, its an armcrest camera. dont believe thats possible. see this thread:


#9

Yep, Amcrest screwed over a whole bunch of loyal customers by disabling a key feature without warning (or documentation), but I’m trying to be technology agnostic here.

So for the sake of this thread, disregard who or what I’m calling and let’s focus on the key premise:

I am able to successfully call this HTTP Request in a browser, and it changed the camera PTZ preset as it is supposed to:

http://user:[email protected]/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0&arg4=0

How to make webCoRE run the above URL? & How do I see the HTTP response?

As shown in my initial post screenshot and logs, it is calling the web request,but nothing’s happening.


#12

Maybe try your external IP address instead of local… also include the port and setup port forwarding.

WAN_IP:Port


#17

there’s an idea. I’ll try that.


#18

i think when you try that from your browser, the browser is routing the request locally to the device. however, when webcore sends the request to ST, ST will not be able to direct that request to the right ip because its executed on the ST cloud and not the ST HUB.


#19

Interesting, I always thought webCoRE ran everything from my local hub.


#20

there is only a handful of DH/apps that ST allows to run locally. the promise of hub v2 was to have more run locally, but that doesnt seem to have been enabled … yet. :slight_smile:


#21

I set up port forwarding and tried it from the external IP:port and it worked!!

I could have sworn I was using the internal IP for blueIris API integration, but for some reason it won’t work with Amcrest.

Thanks a ton Robin, you’ve hooked me up with answers on WebCoRE and Smartthings forums and i truly appreciate it.


#22

great to see you got this working. any reference for the parameter set that needs to be passed in?

http://user:[email protected]/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0&arg4=0

thanks!


#23

tried locally in the browser … doesnt seem to work. even though the armcrest chrome app connects fine with the same ip.


#24

So here’s how it got resolved.

I turned on port forwarding on my router which allows any connection to my publicIP on port XYZ to go to my camera’s private IP port 80.

I tested the call to use the public IP and forwarded port like this:
http://user:pass@publicIp:port/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0&arg4=0

and it worked. But, like most of us, I don’t have a static IP and this call will break when my IP changes. So I signed up for a domain with noip.com which gives me a domain name pointing to my IP address, and the camera can link to noip.com and keep my IP up to date (under setup, network, ddns, set provider to noip.com and give it your creds).

So now my link looks like this:
http://user:pass@mysubdomain.ddns.net:port/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=2&arg3=0&arg4=0

As far as this particular API call, the parameter that matters is arg2 which should be set to your preset ID.
Here’s the API doc:
imagehttps://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf

it’s on page 143 “PTZ control command”


#25

The whole dynamic IP thing can be a PIA!

I used to get a free static IP from my ISP (Virgin) but last year they changed the service to be for Business customers only!!

That said, my IP has only changed once in the year since and that was after my router / modem hub packed in and needed to be replaced.

I’ve setup a series of global variables in WC so changes can be made quickly, just in case:

  • WAN_IP
  • BI_LAN_IP
  • BI_Port
  • BI_User
  • BI_Pass

Then I just reference the variables in the URL string entered into the ‘make a web request’ box.


#26

thanks guys. that will help later for ddns and setting up the rest.

for now I am just trying to get it to work locally on the browser. I can’t seem to get that to work … any tips?

thanks!


#27

What browser are you using? I am using Chrome. I was unable to pass the uesrname and password in the URL to Blue Iris, but for some reason it worked just fine with Amcrest camera.

Also, which camera are you trying to run it on? Does it give you an error, an authentication popup asking for your Username and Password, or just nothing at all?


#28

safari on a mac.

“Safari Can’t Open The Page”


#29

ok, that’s the same camera I’m using, so it should work. Let’s try a couple things:

  1. If you are using your LAN ip (usually 192.168.x.x or 10.x.x.x) you will have to be connected to the same physical network as your camera (i.e.you can’t connect to that IP if you’re not also connected to the same router)

  2. try doing an API call that doesn’t require any parameters:
    http://user:pass@ip/cgi-bin/configManager.cgi?action=getConfig&name=General
    where user/pass/ip are replaced with your info

  3. try it in a different browser
    I was using Chrome on windows, so maybe Chrome on a mac might work

  4. try it without the :@ part
    if you hit the correct link wihtout the user/pass it should give you an authentication pop up asking you to log in. If you don’t get the popup (which you are not) I am assuming there’s something wrong with the URI you are sending.