Some advice to use properly the JSON API

  • Hi,
    I'm trying to build a little android app for myself, so I can manage my instances.
    I need some info please.
    @Lord-Grey can you tell me if it is possible to aggregate more than 1 json command in a single request ?
    Let's say, I want to switch to instance 1 and then disable LEDDEVICE.
    Currently I need to run 2 requests, with the 2 JSON parts.
    Is it possible to do this in a single request ?
    If so can you show me how ?


    Many thanks.

    • Offizieller Beitrag

    @NeeeeB Via curl you can execute two commands via one session using the --next option (sample below).


    In general, if one woudl like executing commands on instances which are not the default one (instance number 0), then it is required to do the switch instance command and then control action in one session (json-rpc or websocket). While for websocket this is not a problem json-rpc tools often execute every request in one session and the result is that the request is done on instance 0.
    Unfortunately, the current API does not allow to have the instance and action in one command.


    Sample: Following command would disable the LED-Device for instance 1 (e.g. the 2nd instance configured).


    Code
    curl -i -X POST 'http://YOURHOSTIP:8090/json-rpc' --data '{"command" : "instance","subcommand" : "switchTo","instance" : 1}' --next 'http://YOURHOSTIP:8090/json-rpc' --data '{"command":"componentstate","componentstate":{"component":"LEDDEVICE","state":false}}'


    Other API commands, please see here:


    https://docs.hyperion-project.org/en/json/Control.html

  • @Lord-Grey I'm sorry to bother you again, but I have another question about the JSON API.
    In particular, the serverinfo command.
    Let's say I have 3 instances running on my Hyperion.
    Now I do a serverinfo to get infos.
    To what instance are related the infos returned by "Components" ?
    https://docs.hyperion-project.…erverInfo.html#components


    I need to know this, because I use LEDDEVICE to disable leds from an instance (which I find more reliable than disabling the instance).


    Thanks !!

  • going by above it looks like unless you switch to a specific instance then run the -next option, by default you will get the first instance


    so if i understood it correct you would


    Code
    curl -i -X POST 'http://YOURHOSTIP:8090/json-rpc' --data '{"command" : "instance","subcommand" : "switchTo","instance" : 1}' --next 'http://YOURHOSTIP:8090/json-rpc' --data '{"command": "serverinfo"}'


    that should give you the array of components in instance 1 - well in my head it does :roflmao:

  • do a serverinfo query to get the entire JSON and save it to a file, least then you can look through it all and work out what sections you need to target, as it should show you all the specific settings relating to the instances you have on the server

  • I already parse the JSON response ;)
    I'll compare 2 queries, each one with a different instance disabled, to see if the components section is related to the "current" instance.
    Thanks btw.

    • Offizieller Beitrag

    To what instance are related the infos returned by "Components" ?


    If you do not switch the instance, the data for instance 0 will be returned by default.


    Just to reiterate, you need to execute the instance switch and the command in one session!!!
    Otherwise the switch instance will be executed and then the command will be executed independently (which means it will run against instance 0).


    In case you are scripting something, you find the following library useful:
    https://github.com/dermotduffy/hyperion-py

  • If you do not switch the instance, the data for instance 0 will be returned by default.


    Just to reiterate, you need to execute the instance switch and the command in one session!!!
    Otherwise the switch instance will be executed and then the command will be executed independently (which means it will run against instance 0).


    In case you are scripting something, you find the following library useful:
    https://github.com/dermotduffy/hyperion-py


    Wait...are you telling me that switching to an instance, and after that running another request to execute an action on it would fail ?
    Because that is not at all the results I get currently.
    I do a first request to switch to a particular instance, and after that another request to disable LEDDEVICE (or run an effect, or set a color), and everything works as intended...
    Also, thanks for the python library, but I'm writing an Android app in my native language which is Delphi, so it will be no use for me ^^

    • Offizieller Beitrag

    are you telling me that switching to an instance, and after that running another request to execute an action on it would fail ?


    No. The point I tried to make is that the commands executed need to be in the same session.
    If one executes two curl commands in sequence, that is two sessions.
    As it was not clear how you are going to solution your scenario, I just wanted to be on the save side that there is no misunderstanding and wrong expectations....


    e.g. if you use Web-sockets, then you open the web-socket (1 session) and you can run as many commands as you like...

  • No. The point I tried to make is that the commands executed need to be in the same session.
    If one executes two curl commands in sequence, that is two sessions.
    As it was not clear how you are going to solution your scenario, I just wanted to be on the save side that there is no misunderstanding and wrong expectations....


    e.g. if you use Web-sockets, then you open the web-socket (1 session) and you can run as many commands as you like...


    Ah yes I see, sorry for the misunderstanding ;)
    And thanks for the info.

    • Offizieller Beitrag

    @NeeeeB Thanks for asking the API question.
    It triggered that I tested the multi-instance scenario for global objects (e.g. USB-grabber) which resulted into the following finding:
    https://github.com/hyperion-project/hyperion.ng/issues/1189


    LED-Devices should not be affected, as they are instance specific.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!