MakerAPI + hub variable with commas in string

I'm trying to set a hub variable to a string that contains commas. I know that in some cases, MakerAPI uses the commas in its API requests to separate multiple values, and I think this is getting in the way.

Is there a way to escape a comma so it can appear in the string and be saved to the hub variable as part of the string?

Observed:

http://192.168.0.4/apps/api/8/devices/182/setVariable/abc%20def%20ghi

This results in the hub variable being set to the string "abc def ghi" as one would expect. The simplest case. Now, inject a comma after "def":

http://192.168.0.4/apps/api/8/devices/182/setVariable/abc%20def%2C%20ghi

and

http://192.168.0.4/apps/api/8/devices/182/setVariable/abc%20def,%20ghi

Whether the comma is URL-escaped or not, the string assigned to the variable is only "abc def", the comma and "ghi" are dropped. I've also tried the ubiquitous \, escape (leading backslash), to no avail (the backslash appears in the string, but the comma and all after are omitted).

1 Like

You can do this with an endpoint in Rule Machine (either local or cloud). It would look like this:

http://192.168.0.45/apps/api/31987/trigger/setHubVariable=stringV:a,b,c?access_token=xxxx

That sets variable stringV to a,b,c.

See Rule Machine API for details.

3 Likes

OK. So I guess I'm having a not-clueful morning here. I can see I need an access token. I can see in the linked thread that someone else asked where the access token can be found, and you pointed them to the head post, and they replied they found it. I am not so blessed. For the life of me, I do not see in the head post where the access token is found. Pointer?

Edit: FOUND! For the benefit of anyone else reading, it's "Cloud End Point" under "Select trigger events" in the rule. (I'm obviously not a RM user)

1 Like

Yeah, right click on the link offered up, and grab the link. Then you can edit the link as needed.

One presumes you can string several /setHubVariable= commands together in a single GET request?

One presumes incorrectly.

2 Likes

So, just for the sake of rounding out the thought a bit there...

I think the embedding of the commands in the URL path rather than as query parameters (or body data in a POST) is an interesting approach. But, if the common 2048 character limit applies to the URL length, that's a hard ceiling on what can be done in one request. Not that I'd push things that far, but you never know what someone might do. :slight_smile:

1 Like

Well, a String variable has a maximum length of 256 characters, so that's not an issue here.

But to your point, some people always want to push the Hubitat platform beyond its design envelope, as if it were some generalized computing device that should have no intrinsic limits. But that's not what it is. So it does have limits, and it is possible to come up with things it won't do.

4 Likes

If I've understood what @LibraSun suggested, you can string several setHubVariable invocations, and perhaps other commands, onto a single request URL... and in that case, it is plausible to reach or exceed the 2048 byte limit, regardless of the string length limit. It's unlikely, and a dumb thing to do, but it does seem possible.

1 Like

No, you can't. He was wrong.

3 Likes