Send GET including %device% in URL

I have a rule that is triggered when one of my many temperature towers value(s) change. The action is a Send HTTP request which (ideally) looks similar to:

myIP/apps/api/appID/tower/%device%/%value%?access_token=xxxxxxxx

While the %device% and %value% works when using Send or Speak a Message it does not appear to work when using Send HTTP Get specifically because %device% is not replaced with the actual value. Is there a way around this?

I don't know why it wouldn't work, but you could put the bulk of the URL into a local variable as you have it and just use the local variable in the URL instead. I remember having to do something similar once, but I don't have those rules anymore to check

1 Like

You must show the actual rule for context. Please add an action to log the uri string so we can see that.

The issue is with the device name I use. For example "Backyard Tower". This fails however... If I rename (or remove spaces) the device to "BackyardTower" it works.

Refresh my memory. Is %device% the device NAME or device LABEL? If its the former my problem is an easy fix by simply removing all spaces.

Device Label.

1 Like

Can you explain what "fails" means? Do you have some error in your hub logs?

2 Likes

No errors on server/client side that I can see but I have confirmed the issue is with spaces in the device name (or URL for that matter) . Here is the rule

With a device label of "Backyard Tower" with a temerature value of 32.4, the rule sent is
http://192.168.1.129/apps/api/xx/tower/Backyard Tower/32.4?access_token=xxxxxxxxx
which fails. Renaming this device to "BackyardTower" or "Backyard_Tower" and all is good.

I think I'll just take all the spaces out of the label name.

I thought I read somewhere that RM has a urlEncode function or something similar. Maybe try that so the spaces will be properly encoded.

It didnt seem to make any difference in my case. For giggles (& having nothing better to do) I decided I would replace all spaces in the device label names with %20. As I suspected, after doing this all worked as it should :slight_smile:

This should handle the blanks in device name:

1 Like

I tried that but it does not seem to work. Using the rule I posted above, here is what the Rule log looks like. At the receiving end of the GET I get nothing,

If I take the same rule/device/etc, substitute devce/value I end up with

http://192.168.1.129/apps/api/56/tower/Garage%20Tower/14.8?access_token=xxxxxx

Pasting this into the address bar of a browser and all is good