Hei vieras, tervetuloa!

Näyttää siltä, että olet uusi täällä. Kirjaudu sisään tai rekisteröidy aloittaaksesi.

Developer API - any ETA?

jannylundjannylund Member Viestejä: 13
Finally purchased Cozify thanks to Lähivakuutus. First impressions are that it looks very nice on paper, but it's extremely locked down.

From the forum, it seems there have been many promises on providing an open API, but so far the only solution seem to be the unofficial python API. Are there any status updates at all on this? Overall it seems that Cozify has one of the most competent hardware solutions that covers a lot of sensors, but without an API it means I can either limit myself to what the app supports, or just go with something else.

Viestejä yhteensä

  • samppasamppa Member, Cozify Viestejä: 651 mod
    We have given the API docs and Python examples under NDA to some selected developers since the SDK is not yet robust enough that releasing it publicly would not cause too much support overhead.

    What kind of features you would be implementing?

    Best Regards,
    Samppa / Cozify
    t. Samppa \ Cozify
  • jannylundjannylund Member Viestejä: 13
    Samppa: Primarily I'm interested in an integration to node-red, to that way allow integration to anything. (homebridge, etc). Of course the optimal solution would be covering also streaming of events out from Cozify.
  • JuneliJuneli Member Viestejä: 5
    Any updates on this?
  • samppasamppa Member, Cozify Viestejä: 651 mod
    The API can be given to competent developers upon request with plans of usage and NDA.
    For example the developer Artanicus of the "unofficial python API" has our API documentation already.
    https://github.com/Artanicus/python-cozify
    t. Samppa \ Cozify
  • samppasamppa Member, Cozify Viestejä: 651 mod
    By the way, if some developer is capable of implementing e.g. Android widget for direct scene control we would gladly release the API for him or her.
    t. Samppa \ Cozify
  • Kimmo SaariKimmo Saari Member Viestejä: 5
    editoi heinäkuu 2018
    samppa kirjoitti:

    By the way, if some developer is capable of implementing e.g. Android widget for direct scene control we would gladly release the API for him or her.

    Well i'm not about to create an Android widget, but i'd really much like to play around with Cozify API. Who knows if i'd end up creating a web or desktop client for it eventually? Either way i'd like to start small, like creating a NodeJS Cozify API Client and perhaps later on start building React application(s) on top of that.
  • samppasamppa Member, Cozify Viestejä: 651 mod
    Send an email to tuki@cozify.fi detailing your plans and possible outcomes and how that benefits the community (e.g. through public Git repo where the source code will be well documented).
    Attach also your contact details (name, SSN, address, phone and email) so that I can prepare an NDA and after that has been signed I can send you the API with a few examples.

    Later on our plan is to streamline this process and open the API to everyone, but since that requires a bit more effort, we have to limit the access to those developers that most probably can achieve something useful without excess need for support.

    - Samppa / Cozify
    t. Samppa \ Cozify
  • jannylundjannylund Member Viestejä: 13
    samppa kirjoitti:

    Send an email to tuki@cozify.fi detailing your plans and possible outcomes and how that benefits the community (e.g. through public Git repo where the source code will be well documented).
    Attach also your contact details (name, SSN, address, phone and email) so that I can prepare an NDA and after that has been signed I can send you the API with a few examples.

    Later on our plan is to streamline this process and open the API to everyone, but since that requires a bit more effort, we have to limit the access to those developers that most probably can achieve something useful without excess need for support.

    - Samppa / Cozify

    One and a half years later, nothing seems to have happened? I'm still waiting for the NDA and API documentation as promised on 2017-09-13.
  • jannylundjannylund Member Viestejä: 13
    Using the python-cozify lib, I wrote a quick wrapper that forwards all sensors to mqtt. This allows me to at least visualize data, but controlling seems to be a no go for now. (At least via python-cozify, and I haven't found any other examples)
  • samppasamppa Member, Cozify Viestejä: 651 mod
    @jannylund Sorry for forgetting to follow up your ticket at the support.
    But I have some good news as the apidoc has been developed further.
    I will answer now to your ticket and you will get access to the documentation.

    Soon we will publish it for everyone.

    Best Regards,
    Samppa

    t. Samppa \ Cozify
  • jannylundjannylund Member Viestejä: 13
    @samppa Thanks, I appreciate finally getting access to this information. Is there any suggestion on how to send requests on things that would be nice to have in the api?
  • samppasamppa Member, Cozify Viestejä: 651 mod
    What programming language and environment you are using?

    I tried it myself with Java in Android Studio using javax.net.ssl.HttpsURLConnection class and succeeded to login and access the API calls.

    The documentation of Cozify API is not yet very thorough, so e.g. be careful with the "Content-type" and "Accept" headers that define the type of data sent or received ("application/json" or "text/plain") that varies depending on the API call. So admittedly the API is not very coherent.

    The login sequence is as follows with some additional hints to avoid some of the most common caveats:

    1. Emit temporary password to email with
    https://api.cozify.fi:/ui/0.2/user/requestlogin?email=user@cozify.fi
    call POST with email added to the URL and empty payload data and "text/plain" in "Content-Type" and "Accept" headers.

    2. Once user has entered the password, confirm it with
    https://api.cozify.fi/ui/0.2/user/emaillogin
    call POST with data payload JSON as follows: {"email": "user@cozify.fi", "password": "XXYYZZ"} So this time Content-Type is "application/json" and "text/plain" as Accept the header. Return value is a string that you store as cloudtoken to be used as the "Authorization" header is all further calls.

    3. Next you list all the hubs the user can control with
    https://api.cozify.fi/ui/0.2/user/hubkeys
    call GET. It returns JSON, so the "Accept"-header needs to be "application/json". Parse the returned JSON array of hub identifiers and JWT tokens to be also stored and used in all further calls to that hub as "X-Hub-Key" additional header field. Also you should decode the JWT by splitting the string with '.' delimiter and base64 decoding the parts to get JSON. The second part contains information about the hub e.g. the hub_name field that you need for listing the hubs to end user.

    Now you have all the info needed for calling all the other commands to e.g. devices.
    And if you store the tokens securely, you can avoid the login each time and re-use them for 4 weeks.

    Easy start is to use all calls always through the cloud remotely, but you can also send the commands directly to the hub if connected in the same LAN (there is a simple call "https://api.cozify.fi/ui/0.2/hub/lan_ip" to discover if there are any hubs in the same lan available).


    BR,
    Samppa \ Cozify
    t. Samppa \ Cozify
  • jannylundjannylund Member Viestejä: 13
    @samppa no worries with the techinal parts. I'm mainly a Java / Scala developer, but these days I'm mostly writing things like this in python.

    My main worry is that it's tricky to since it requires semi-interactive login. Say for example an cozify 2 mqtt proxy could rather easily be written with your existing API, but if I want to run it in docker / kubernetes / etc, it's a bit complicated to do the initial login. It would be great if you had the option to generate a permanent api key that is not time restricted for these kind of cases. (preferably also a possibility to limit the key to read only calls)
Kirjaudu sisään tai Rekisteröidy kommentoidaksesi.