REST API error after updating to Indigo 2022.2.0

Posted on
Sat Mar 04, 2023 8:13 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

REST API error after updating to Indigo 2022.2.0

We are using a couple of Rest API commands but they are not working anymore with Indigo 2022.2.0

For example this one:

Code: Select all
#!bin/sh

/usr/bin/curl -u Name:Passwords --digest -X PUT -d value=true http://192.168.178.221:8176/variables/CarInGarage


Gives the error:

Code: Select all
⚠️ 405 — Method Not Allowed
===========================
Method PUT not allowed for URL /variables/CarInGarage


(and also some very nice scripts which are working with Carbon Copy Cloner to display the actual status of the most recent backup with time at a control page)

They also doesn't work anymore.

What's the solution for this problem?
Thanks for your support.

Posted on
Sat Mar 04, 2023 8:53 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: REST API error after updating to Indigo 2022.2.0

PS:

And what's the solution to update a date and time variable with Indigo 2022.2.0?
The old one was:

Code: Select all
/usr/bin/curl -u Name:Passwords! --digest -X PUT -d value=$(date +start@:%d_%m-%H:%M) http://192.168.178.221:8176/variables/CCCBackupDate


Thanks for the support.

Posted on
Sat Mar 04, 2023 9:19 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: REST API error after updating to Indigo 2022.2.0

You may find this article helpful: REST API Conversion Examples

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Mar 04, 2023 10:00 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: REST API error after updating to Indigo 2022.2.0

Thank you so much for the fast reply Dave!

I've seen that but that solution needs a reflector key. It's a pity that the Rest Api feature apparently suddenly removed from the new version.
It worked very well for years and for an internal solution at the same Mac it was perfect!
(it needed no complex detours)

Anyway, do you know what the JSON code is for this:

Code: Select all
/usr/bin/curl -u Name:Passwords! --digest -X PUT -d value=$(date +start@:%d_%m-%H:%M) http://192.168.178.221:8176/variables/CCCBackupDate

(to display the date and time into an Indigo variable). Tried this: $now() but that won't work.

Thanks for your support.

Posted on
Sat Mar 04, 2023 11:04 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST API error after updating to Indigo 2022.2.0

There's been an action to insert a date/time stamp into a variable for several years now, so I would just put it into an action group then just execute the action group from your shell script:

Code: Select all
curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.actionGroup.execute","objectId":123456789}' http://127.0.0.1:8176/v2/api/command


Of course, you need to insert your API Key, action group ID, and ip address (if not running on your Indigo server).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 11:26 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: REST API error after updating to Indigo 2022.2.0

Thanks for the solution and fast answer.

We are using the " insert a date/time stamp into a variable" for several years but thought this could also with a JSON command?
Or is that over and out now?

Anyway, the Action group is not necessary because we can also made a Trigger when a Variable is changed by an external JSON command (a run script from Carbon Copy Cloner), insert a date/time stamp into a variable".

BTW: good point:
" and ip address (if not running on your Indigo server)."
So, when the command is given from the same Mac, the script NEEDS also always the local IP address?

Posted on
Sat Mar 04, 2023 11:33 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST API error after updating to Indigo 2022.2.0

Well, it can, I just think the action group is a better solution. If you want to do it directly, this is something like you'd do. Note, I'm not a bash guy, so I have no idea how the substitution would actually take place in a shell script. Check out this conversion section for an example - you just need to figure out how to substitute the date from bash in place of 1.23 in the example - that's where you'd put the date string value.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 11:37 am
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST API error after updating to Indigo 2022.2.0

Forgot to answer this one:

McJohn wrote:
So, when the command is given from the same Mac, the script NEEDS also always the local IP address?


Like anything else, you can use loopback, the actual IP address, the Mac's Bonjour name, or the reflector (though that would be a slower round trip).

It's just like any http address, and was no different in the REST API.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 12:16 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: REST API error after updating to Indigo 2022.2.0

In the zsh shell, the syntax is:
Code: Select all
echo $(date +%d.%m.%y-%H:%M:%S)
or whatever date format you'd like.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Mar 04, 2023 12:50 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: REST API error after updating to Indigo 2022.2.0

Ok..Switched to using the HTTP API and I am once again getting updated Indigo vars.

However, two issues. First, for anyone doing this in a shell script (I.e. using curl), and using shell variables in the update, here is an example of the correct syntax. (Hint, shell vars will not be expanded between single quotes):
Code: Select all
curl -X POST -H "Authorization: Bearer <API-KEY>" -d '{"message":"indigo.variable.updateValue","objectId":12345,"parameters":{"value":"'$TIMESTAMP'"}}' http://127.0.0.1:8176/v2/api/command
Notice the added single quotes around the var.

Second, I am seeing the following in the Indigo log on each update:
Code: Select all
Web Server                      HTTP API command call received from 127.0.0.1
   Web Server                      API v2 command received, id: '- no message id -' from '127.0.0.1'
a) I would like to suppress these messages altogether, and
b) If I were to want one, how would I enter a message Id? I tried a number of names, like messageId, and none worked.

BTW, for a timestamp I use a slight variation on Dave's suggestion:
Code: Select all
TIMESTAMP=$(date "+%Y-%m-%d-%H:%M:%S")


EDIT: A bit of searching for the message id turned up viewtopic.php?p=216631#p216631
Thanks Dave.

Posted on
Sat Mar 04, 2023 1:02 pm
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: REST API error after updating to Indigo 2022.2.0

DaveL17 wrote:
In the zsh shell, the syntax is:
Code: Select all
echo $(date +%d.%m.%y-%H:%M:%S)
or whatever date format you'd like.


Thanks for the hint Dave (and the European Date Service :wink: ).

Tried this:
Code: Select all
curl -X POST -H "Authorization: Bearer the-very-secret key -d '{"message":"indigo.variable.updateValue","objectId": 660038,"parameters":{"value":"echo $(date +%d.%m.%y-%H:%M:%S)"}}' http://127.0.0.1:8176/v2/api/command

But then that Indigo Variable is filled with this text: $(date +success@:%d_%m-%H:%M)

For example this one works perfect:
Code: Select all
curl -X POST -H "Authorization: Bearer the-very-secret-key -d '{"message":"indigo.variable.updateValue","objectId":1033915322,"parameters":{"value":"blue"}}' http://127.0.0.1:8176/v2/api/command

Posted on
Sat Mar 04, 2023 1:09 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: REST API error after updating to Indigo 2022.2.0

McJohn wrote:
...
But then that Indigo Variable is filled with this text: $(date +success@:%d_%m-%H:%M)
...
Exactly :D Take a look at my post just before yours. You need:
Code: Select all
curl -X POST -H "Authorization: Bearer the-very-secret key -d '{"message":"indigo.variable.updateValue","objectId": 660038,"parameters":{"value":"'echo $(date +%d.%m.%y-%H:%M:%S)'"}}' http://127.0.0.1:8176/v2/api/command
But, probably easier to put it into a variable like in my example.

Posted on
Sat Mar 04, 2023 1:16 pm
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: REST API error after updating to Indigo 2022.2.0

Thanks for the extra input Berkinet!

This one does the trick!:

Code: Select all
curl -X POST -H "Authorization: Bearer very-secret-key -d '{"message":"indigo.variable.updateValue","objectId": 660038,"parameters":{"value":"'$TIMESTAMP$(date "+%Y-%m-%d-%H:%M:%S")'"}}' http://127.0.0.1:8176/v2/api/command


Very happy that this is solved! :D
Last edited by McJohn on Sat Mar 04, 2023 1:46 pm, edited 1 time in total.

Posted on
Sat Mar 04, 2023 1:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: REST API error after updating to Indigo 2022.2.0

berkinet wrote:
Code: Select all
Web Server                      HTTP API command call received from 127.0.0.1
   Web Server                      API v2 command received, id: '- no message id -' from '127.0.0.1'


We have an enhancement request to think about various message suppression options. The old web server always logged API commands to the event log as a security measure.

berkinet wrote:
If I were to want one, how would I enter a message Id? I tried a number of names, like messageId, and none worked.


I think all command messages described in the new API Doc include "id".

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Mar 04, 2023 1:44 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: REST API error after updating to Indigo 2022.2.0

jay (support) wrote:
...I think all command messages described in the new API Doc include "id".
Thanks, I see that now. I was going by the document DaveL linked earlier in this thread: REST API Conversion Examples. Id is not mentioned there.

EDIT, In fact, only the WebSocket API section of that doc mentions "Id" The HTTP API does not include that.

Who is online

Users browsing this forum: No registered users and 8 guests