Python API routines?
  • Hey, has anybody written any python code to pull data from the API?  Would be cool if we had a library out in Github or somewhere like that.  

    I'm looking to pull responder data from here to merge with my CAD incident import to Firehouse Software.  Until I get to playing with the API, I can't really discern what's possible.  Can I request alert data by "cad_code", or do I just have to iterate through all available alerts until I find the right one?
  • Hi Bucky,
    I have not personally written any Python code to pull data from the API. I'm sure you have probably been looking at the API, but here is our documentation for it.


    We do have examples for PHP, Java, and Javascript under the Developer API Examples section. As long as you are familiar with Python and one of those three languages, it shouldn't be too difficult. If you run into any hurdles, please let me know specifically what they are and we will help out. Also, if you aren't familiar with OAuth, it would be helpful to familiarize yourself with it since that is what the Developer API uses for authentication.

    In response to your last question, with the way the API is currently setup, you will have to iterate through alerts in order to filter them by cad_code.

    Please share what you learn and maybe we can update our documentation with some Python examples if you share that as well.

    Thanks!
  • Thanks for the reply Robert!  I'll fight through translating the examples into Python.  Shouldn't be too difficult, other than I'm a bit of a Python novice (my background is in mainframe programming).   Also have to learn oAuth, but that's a one-and-done type thing.

    Thanks for the info about the cad_code. Thinking maybe I'll just dump the responder data into a SQLite DB on my side to make it easier to correlate with our incident numbers.

    I'll pop back in occasionally with updates (and probably more often than that with questions!).

    Thanks!
  • Well, first question!  Is there any place I can determine a static mapping of device ID to member name?  I'm gonna have to build a table that maps the A911 Device code to Member Name to Firehouse Software Staff ID.  Is this exposed in the A911 management GUI?  I can't find it.  I suppose I could build code to do it or manually build URLs based on devices listed in the "Agency" API call, but I'd rather just manually build the table.

    Thanks!
  • I'm not sure if this will help, but the device ID is actually the first part of the device code. If you can get a list of devices with their device codes, you can just take the part of the code before the dash (they should always be the only numbers) and that's the device ID. I don't think you can get this through the open api right now, but you can find it under the devices tab on the website.
  • The API does not return the full device code. A device code is the device id followed by a secret key for that device separated with a dash. With this knowledge, the device Id may be sufficient to do what you want.

    I also wanted to share with you a project that uses the API which one of the developers on our team wrote. It is 100% PHP, but may be a useful example.

  • Thanks Paul, thanks again Robert!  

    I made out pretty decently with my Python code.  In fact, you guys did such a good job structuring data it was easy!  Toughest part for me was figuring out oauth.  (Worked fine for the first day, then stopped working!!  :) ).  Of course, I just had to figure out how to put together a post request for a new access token.  And since this was the first API I attempted to use without a wrapper library it took me a bit to interpret the docs here and figure out that I actually NEEDED to do "put" and "post" requests!!  

    It turned out to be so simple that I ended us just writing a short script to list all device ID's. 17 lines is all it took!  As soon as I figure out how to fix an embarrassing line (I can't yet figure out how to pass a variable into a requests.post request) I will post it up here for all to laugh at!!   Anyone with agency permissions will be able to just pop in their refresh token and it should work to list all their agency deviceIDs.