received an API command message with an invalid JSON payload

Posted on
Mon Mar 13, 2023 7:05 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

received an API command message with an invalid JSON payload

Hello,

I use the app BetterTouchTool and this works:
Code: Select all
do shell script "curl --digest -u 'USER:PASSWORD' http://192.168.1.14:8176/actions/Remote_Buddy_Menu?_method=execute"


The app is preventing the use of double quotes inside the do shell script.

Trying:
Code: Select all
do shell script "curl -X POST -H 'Authorization: Bearer API-KEY' -d '{'message': 'indigo.actionGroup.execute','objectId':1573095203}' 192.168.1.14:8176/v2/api/command"


It gives me the Web Server Error and Web Server Warning HTTP 400 error for request /v2/api/command from 192.168.1.14

The App returns with {"request_body":"{message: indigo.actionGroup.execute,objectId:1573095203}","error":"invalid JSON"}

I tried all kinds of variations with the use of quotes but nothing works.

Who can help.

Greetings, Adrian

Posted on
Mon Mar 13, 2023 8:34 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: received an API command message with an invalid JSON pay

JSON doesn't allow single quotes to be substituted for double quotes, and AppleScript doesn't allow the opposite. So, you have to construct your command line using escapes:

Code: Select all
do shell script "curl -X POST -H 'Authorization: Bearer API-KEY-HERE' -d '{\"message\": \"indigo.actionGroup.execute\",\"objectId\": 64217936}' http://YOUR-IP-ADDRESS:8176/v2/api/command"


I suspect that you don't need to do it from an AppleScript though since I'm pretty sure that BetterTouchTool will also do shell scripts so it might be possible to just do the curl command directly (but I'm speculating since I don't use BTT).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Mar 13, 2023 11:31 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: received an API command message with an invalid JSON pay

Thanks Jay, that made it work again.

You are right about BTT doing shell script.
I tried it but works slower then applescript.

I use BTT with a Siri Remote.
First impression is that the new HTTP API is less snappy then the old way!

I will keep monitoring. Ik hope I get back the snappy responce times.

Maybe there are some tips to speed things up?

Posted on
Mon Mar 13, 2023 2:21 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: received an API command message with an invalid JSON pay

It should be faster - the new web server we're using is significantly better than the old one (which all of our testing shows), so I'm not sure why it would be slower for you.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 15, 2023 4:01 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: received an API command message with an invalid JSON pay

Testing the slow responce but no change.

Using 2022.2,-> button press, results is a 1 second delay.
Using 2022.1 -> button press is an instant reaction

Tried it several times and the outcome is always the same.
Using applescript or shell script from BTT makes no difference.
Using Terminal on the host or other mac to test and still a 1 second delay.

macOS 10.15.7
MacMini (late 2012)
BTT and and indigo server are on the same mac.

Posted on
Wed Mar 15, 2023 12:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: received an API command message with an invalid JSON pay

How exactly are you sending the old command and the new command? Copy/paste the code/url/whatever for each (remove any credentials).

Also, when you go to the new Indigo Touch for Web interface, is there any delay when you turn on/off the same device?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 15, 2023 1:39 pm
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: received an API command message with an invalid JSON pay

2022.1 instant action with
Code: Select all
    do shell script "curl --digest -u 'USER:PASSWORD' http://192.168.1.14:8176/actions/Remote_Buddy_Down?_method=execute"


2022.2 1 second delay with
Code: Select all
    do shell script "curl -X POST -H 'Authorization: Bearer API-KEY' -d '{\"message\": \"indigo.actionGroup.execute\",\"objectId\": 1673871159}' http://192.168.1.14:817/v2/api/command"


Web interface is instant action

Posted on
Wed Mar 15, 2023 1:57 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: received an API command message with an invalid JSON pay

And what exactly does "Remote Buddy Down" do?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 15, 2023 2:18 pm
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: received an API command message with an invalid JSON pay

I use a Siri Remote with BetterTouchTool.
On buttonpress it executes the actiongroup 'Remote_Buddy_Down' in Indigo.
It in turn toggles a variable 'Down' between true/false.
A trigger checks the change and depending on a scene (watch TV, Listen music, watch movie) it sends a command to a specific device.

I could replace indigo.actionGroup.execute in the curl command with a variable action to test if there is any change in response time.
But I don't know if there is a command in HTTP API to toggle a variable.

Posted on
Thu Mar 16, 2023 9:16 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: received an API command message with an invalid JSON pay

We are adding some caching features in the next maintenance release (2022.2.1) which we believe will speed up some API calls.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Mar 17, 2023 7:41 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: received an API command message with an invalid JSON pay

I did a clean install and made a fresh user account to rule out that anything was interfering.
Still getting the 1 second delay with the HTTP API.

If you want me to test something please let me know.

Hoping the next release comes soon.
In the mean time I will revert to 2022.1 till there is a solution.

Posted on
Fri Mar 17, 2023 4:00 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: received an API command message with an invalid JSON pay

Yes, we are pretty sure this will be addressed in the next bug fix release of Indigo.

Image

Posted on
Tue Apr 04, 2023 3:16 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: received an API command message with an invalid JSON pay

This should be addressed in the just released 2022.2.1 release.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Apr 05, 2023 10:33 am
Vaillant offline
Posts: 105
Joined: Nov 06, 2011
Location: Belgium

Re: received an API command message with an invalid JSON pay

Issue is solved.
Response time is back to normal with 2022.2.1.

Posted on
Wed Apr 05, 2023 4:32 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: received an API command message with an invalid JSON pay

Great, thanks for the confirmation.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests