Maker API setGlobalVariable

I'm attempting to set a Global Variable (AlertMessage) via a Maker API. I found the format pursuing the community, but when I attempt to use it I get an error.

URL:

http://192.168.1.4/apps/api/386/trigger/setGlobalVariable=AlertMessage:abcdefgh?access_token=xxxxx

Return:

{
"error": true,
"type": "AppException",
"message": "Not Found"
}

URL of course works with devices.

What am I doing wrong? (it's usually the loose nut behind the keyboard that is the issue...)

Alan

I think you need to use Rule Machine as the http endpoint device to set a Global Variable, not Maker API...:thinking:

See the following thread for details...

One method is to create a GV connector and then add the connector to the Maker API. You can then access it the same as you would any other device. Just make sure your entry is in the proper format if you're doing a time variable. Has to be in the proper format of it will totally hose your variable.

1 Like

I was able to set it using the Maker API locally. Now to try Cloud.

http://192.168.1.4/apps/api/386/devices/837/setVariable/abcdefg?access_token=xxxxx

1 Like

As noted below I got it to work using the Maker API since I already had a connector created, but am still working on the rule machine. My current issue is how to get the appid for the Rule Machine. I usually look at the log, but rule machine doesn't create any log entry.

I believe you have to create an http endpoint trigger in RM, and that will then display the correct http url for you to use. I am not an expert on this, so others who have actually done this may want to chime in and assist.

Are you able to parse data from that though? I thought you could only use that as a trigger event.

RTFM (Italics are mine):

Using Rule Machine from HTTP requests

It is also possible to cause Rule Machine to perform these same actions from an HTTP request. To do this one would create a Trigger or a Triggered Rule with either a Local End Point or Cloud End Point. The endpoint URL given by Rule Machine has this form:

http://192.168.0.36/apps/api/10249/trigger?access_token=ecd95469-bbcd-4889-a694-9b05ef80f4db

To run rule actions this URL must be modified to include the list of rules and the action. The modification takes this form:

/action=rule1&rule2&rule3

Where action is the action from the list above and rule1&rule2&rule3 are the appIds of the rules to run separated by ampersands.

This parameter is inserted in the endpoint URL just before the ? that precedes the access_token, like this:

http://192.168.0.36/apps/api/10249/trigger/stopRuleAct=943&956&10217?access_token=ecd95469-bbcd-4889-a694-9b05ef80f4db

This example would do the same thing as the code example above, where 943&956&10217 are the appIds that were selected by consequence of the input for theseRules, and stopRuleAct is the action to perform.

The appIds are the values selected by the input described above, for example theseRules. The appIds can also be found for a rule by opening the rule and observing its appId in its url, like this:

[http://192.168.0.36/installedapp/configure/10249/mainPage](http://192.168.0.36/installedapp/configure/10249/mainPage`)

The appId for that rule is 10249.

Get Rule List

To get the list of rules as is returned from getRuleList() use this insert for the URL:

/getRuleList

for full URL like this:

http://192.168.0.36/apps/api/10249/trigger/getRuleList?access_token=ecd95469-bbcd-4889-a694-9b05ef80f4db

This returns a JSON object with appId and rule name pairs. The other requests return a JSON object with a human readable description of what was done.

Set Global Variable

A Global Variable can be set by an endpoint trigger. The format for the parameter is this:

/setGlobalVariable=varName:varString

The varString portion is assumed to be URL encoded, and is URL decoded before being stored into the varName global variable.

3 Likes

This part is important if your Variable has any spaces in it. Those will have to be replaced before being sent to the hub and the Maker API will not decode the url-encoded string. So, this is a big advantage to using this method over the maker api.

2 Likes

I don't usually create a variable with spaces. Call me an Old programmer (I won't say I started with Cobol and Fortran using cards).

Thanks All! @ogiewon @Ryan780
Alan

4 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.