streamdeck-api-request icon indicating copy to clipboard operation
streamdeck-api-request copied to clipboard

Unable to find value for JSON path

Open roberthawdon opened this issue 3 years ago • 10 comments

Hi, I'm currently attempting to use this plugin to control my home automation system (Home Assistant)

When using the API to toggle an appliance, the following JSON response comes back from the API:

[
  {
    "entity_id": "switch.desk_lamp_outlet_1",
    "state": "on",
    "attributes": {
      "outlet_in_use": true,
      "icon": "mdi:desk-lamp",
      "friendly_name": "Desk Lamp"
    },
    "last_changed": "2022-12-10T20:15:07.713523+00:00",
    "last_updated": "2022-12-10T20:15:07.713523+00:00",
    "context": {
      "id": "REDACTED",
      "parent_id": null,
      "user_id": "REDACTED"
    }
  }
]

Logic would tell me that the JSON Path for the state value should be $.[0].state or $[0]['state']; however, neither of these are working, and neither is setting the path to state or leaving the path empty and making the plugin look for the expected value of on.

I'm sure there's something simple I'm missing here.

roberthawdon avatar Dec 10 '22 20:12 roberthawdon

@roberthawdon any resolution from your end?

IBC-IT avatar Jan 30 '23 19:01 IBC-IT

@IBC-IT No, in the end I found a better plugin for my use case of controlling Home Assistant: https://github.com/cgiesche/streamdeck-homeassistant

However, for controlling other APIs, this issue would still stand.

roberthawdon avatar Jan 31 '23 00:01 roberthawdon

My apologies for not responding sooner - I've not worked on the plugin since I originally submitted it elgato to be distributed.

The json path code is just the included streamdeck utility javascript, here. It's fairly basic in functionality. I have not tested, but it looks like [0].state might have worked in your instance.

mjbnz avatar Jan 31 '23 00:01 mjbnz

@mjbnz So in my case, with response of: [{"component":"main","capability":"mediaInputSource","command":"setInputSource","arguments":["HDMI3"]}]

Would not the path be [0].arguments[0] to determine whether it's HDMI 1,2,3 etc.?

Still not working in my case...

Screenshot 2023-01-30 at 5 46 51 PM

IBC-IT avatar Jan 31 '23 01:01 IBC-IT

Also, should the "value" fields include quote marks or not?

IBC-IT avatar Jan 31 '23 01:01 IBC-IT

Would not the path be [0].arguments[0] to determine whether it's HDMI 1,2,3 etc.?

Still not working in my case...

Yes, that's how I'd read it. looks like the streamdeck SDK's getProperty() doesn't deal with that correctly (an array at the base).

Absolutely no promises, but I'll try to get some time to look at that this weekend.

Also, should the "value" fields include quote marks or not?

No. it's supposed to be for basic string matching if included. with field defined, it tries to parse as json, without, it looks for the text in the response body. code for that is here.

mjbnz avatar Jan 31 '23 01:01 mjbnz

@mjbnz thank you!

I also don't understand why it does not work when the path is empty, and the value is entered as simply HDMI2 Would that not bypass any array at the base?

IBC-IT avatar Jan 31 '23 05:01 IBC-IT

@mjbnz any hope you had a chance to look at this?

ukiews avatar Feb 10 '23 21:02 ukiews

Has anyone else been able to find a solution?

ukiews avatar Mar 15 '23 19:03 ukiews

Has anyone else been able to find a solution?

I wasn't able to find time last month, more pressing items got in the way. There's a few little items I'd like to sort out with the plugin. Give me a couple of weeks and I should be able to find some time to look into it.

mjbnz avatar Mar 15 '23 21:03 mjbnz