# Socrata University ## API School ![Socrata U](../../img/socrata-u-logo.png) [@chrismetcalf](http://twitter.com/chrismetcalf)
# Who the heck are you? ![APIs](../../img/socrata-white.png)

We build software to make data useful to more people in the ways that are most useful to them.

data.edmonton.ca finances.worldbank.org data.cityofchicago.org data.seattle.gov data.oregon.gov data.wa.gov www.metrochicagodata.org data.cityofboston.gov info.samhsa.gov explore.data.gov data.cms.gov data.ok.gov data.nola.gov data.illinois.gov data.colorado.gov data.austintexas.gov data.undp.org www.opendatanyc.com data.mo.gov data.nfpa.org data.raleighnc.gov dati.lombardia.it data.montgomerycountymd.gov data.cityofnewyork.us data.acgov.org data.baltimorecity.gov data.energystar.gov data.somervillema.gov data.maryland.gov data.taxpayer.net bronx.lehman.cuny.edu data.hawaii.gov data.sfgov.org data.cityofmadison.com healthmeasures.aspe.hhs.gov data.weatherfordtx.gov www.data.act.gov.au data.wellingtonfl.gov data.honolulu.gov data.kcmo.org data2020.abtassociates.com data.ny.gov health.data.ny.gov www.halifaxopendata.ca portal.louisvilleky.gov data.medicare.gov data.southbendin.gov
# So what is an API anyway? ![APIs](../../img/Bubble_blue.tif.png)
Application
Programming
Interface

Common Language

A consistent way for two software systems to communicate.

Stable Platform

A guarantee that the language will not change without notice.

Contract

An API is a contract between a provider and a consumer.
# Why are APIs important? ![APIs](../../img/Gear.png)

Open data is messy

C00000042|ILLINOIS TOOL WORKS FOR BETTER GOVERNMENT COMMITTEE|Michael J. Lynch|3600 W. Lake Avenue||Glenview|IL|60025|U|Q||Q|C|ILLINOIS TOOL WORKS INC|
C00000059|HALLMARK CARDS PAC|Swarens, Greg|2501 McGee|MD #288|Kansas City|MO|64108|U|Q|UNK|M|C|HALLMARK CARDS INCORPORATED|
C00000422|AMERICAN MEDICAL ASSOCIATION POLITICAL ACTION COMMITTEE|WALKER, KEVIN|25 MASSACHUSETTS AVENUE NW|SUITE 600|WASHINGTON|DC|20001|U|Q||M|M|AMERICAN MEDICAL ASSOCIATION|
C00000489|D R I V E POLITICAL FUND, CHAPTER 886|RON COBB|3528 WEST RENO||OKLAHOMA CITY|OK|73107|U|Q||Q|L|TEAMSTERS LOCAL UNION 886|
C00000547|KANSAS MEDICAL SOCIETY POLITICAL ACTION COMMITTEE|C. RICHARD BONEBRAKE, M.D.|623 SW 10TH AVE||TOPEKA|KS|66612|U|Q|UNK|Q|T|MEDICAL ASS'N; KANSAS          [AMPAC]|
C00000638|INDIANA STATE MEDICAL ASSOCIATION POLITICAL ACTION COMMITTEE|Kora, M.D., Vidya|322 Canal Walk, Canal Level|.|Indianapolis|IN|46202|U|Q||Q|M|Indiana State Medical Association|
C00000729|AMERICAN DENTAL POLITICAL ACTION CMTE.|Triftshauser, Roger W|1111 14th Street NW|Suite 1100|Washington|DC|20005|U|Q|UNK|M|T|DENTAL ASS'N; AMERICAN|
    
Courtesy of ftp.fec.gov
## A downloaded dataset is a stale dataset ![Clock](../../img/Alarm_clock.tif.png)
## Developers don’t want to manage custom datastores ![Hockey Puck](../../img/Database.tif.png)
## You want apps to be easily portable ![Rocket](../../img/Rocket.tif.png)
# The Socrata Open Data APIs ![SODA](../../img/can.png)

Every dataset, on every Socrata data site


GET https://data.seattle.gov/resource/fire-911.json?$where=datetime > '2012-08-22 15:45'
[
  {
    "address": "1402 E Pike St",
    "longitude": "-122.314118",
    "latitude": "47.614121",
    "incident_number": "F120079189",
    "datetime": 1345675560,
    "type": "Motor Vehicle Accident",
    "report_location": {
      "longitude": "-122.314118",
      "latitude": "47.614121"
    }
  }
]
    
## Open, standards-based, non-proprietary * Simple, RESTful, APIs for each dataset * SQL-like query syntax * `JSON`, `XML`, `RDF-XML`, `CSV` * Open Source client libraries
# The Socrata Consumer APIs ![Socrata University](../../img/can.png)
## RESTful Resources * Accessed using [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) paradigms * Use standard HTTP verbs (`GET`, `POST`, `PUT`, `DELETE`)

API Endpoints

Format: https://$domain/resource/$identifier.ext

API Endpoints

Example: Electric Consumption by Zip Code https://data.city.gov/envir.../elec.../abcd-1234 ... becomes ... https://data.city.gov/resource/abcd-1234.json

Simple Filters

/resource/abcd-1234.json?source=ConEd
[ {
  "zipcode" : "10001",
  "source" : "ConEd",
  "location" : {
    "longitude" : "-73.99688630375988",
    "latitude" : "40.75025902143676",
  },
  "building_type" : "Commercial",
  "kwh" : "23328498"
}, ... ]
    

SoQL Queries

/resource/abcd-1234.json?$where=kwh > 80000 For more details see dev.socrata.com

Aggregating Data

/resource/abcd-1234.json?
$select=source, sum(kwh)
&$group=source
[ {
  "source" : "ConEd",
  "sum_kwh" : "49469570957"
}, {
  "source" : "Long Island Power Authority",
  "sum_kwh" : "445333629"
}, ... ]
    

Limiting Output

/resource/abcd-1234.json?
$limit=5

Paging Through Data

/resource/abcd-1234.json?
$limit=50
&$offset=100

Application Tokens

  1. Register at http://dev.socrata.com/register
  2. Include as:
    • X-App-Token: $token HTTP Header or ...
    • The $$app_token=$token parameter
  3. Profit!!! (from more API requests)
## Open Source Code * Libraries in: * Ruby * Java * Scala * ObjectiveC / iOS * Our entire backend stack * ... and more! ![opensource](/presentations/img/socrata-heart-opensource.png) ### [http://github.com/socrata](http://github.com/socrata)
# API Foundry ![Gear!](../../img/Gear.png)
## API Foundry The best way of making your API deployment effort successful rapidly and easily: * Create a customized, friendly API * Custom documentation and code samples automatically created * Powerful API management and throttling tools [http://www.socrata.com/api-foundry/](http://www.socrata.com/api-foundry/)
# Demo! ![Experiment](../../img/Pipette.tif.png)
# Publishing Strategies ![Strategies](../../img/Notebook.tif.png)
## Archival Dataset? ## Infrequent Changes? There's no need for an API integration. Use the web tools!
## Daily or Weekly Updates? ## Complete replacement? ## Comes from an ETL system? Use the bulk replace API or the FTP Dropbox
## Real-time updates? ## Data that morphs over time? Use the RESTful API
## Don't have in-house developers? ## Prefer an off-the-shelf solution?

Use the Safe Software's FME Product or Socrata DataSync

For more details attend the Socrata Integration course

# The Socrata Publisher APIs ![Gear!](../../img/Gear.png)
## Overview Follows the same paradigms as the consumer APIs: * Same `REST`ful endpoint as the dataset * Supports `JSON`, `XML`, `CSV`, etc. * Bulk and metadata update interfaces also available

Example: Adding a new fire 911 report


POST https://data.seattle.gov/resource/kzjm-xkqj.json
Content-type: application/json
Authorization: Basic [REDACTED]
X-App-Token: CGxaHQoQlgQSev4zyUh5aR5J3
[
  {
    "address": "1402 E Pike St",
    "longitude": "-122.314118",
    "latitude": "47.614121",
    "incident_number": "F120079189",
    "datetime": 1345675560,
    "type": "Motor Vehicle Accident",
    "report_location": {
      "longitude": "-122.314118",
      "latitude": "47.614121"
    }
  }
]
    
## Publisher Client Libraries Libraries or examples available for: * [Java](https://github.com/socrata/soda-java) * [Scala](https://github.com/socrata/soda-scala) * [Ruby](https://github.com/socrata/soda-ruby) * More coming soon... [http://github.com/socrata](http://github.com/socrata)
# Other Resources ![Gear!](../../img/Rocket.tif.png)
## Hackathon-in-a-Box ![Box](../../img/Box.tif.png) [http://hackathon-in-a-box.org](http://hackathon-in-a-box.org)
## Native SDKs ![Apple](../../img/apple.png)![Android](../../img/android.png)
# Getting help ![Questions](../../img/Question.tif.png)
## Developer portal ![dev.socrata.com](../../img/dev_socrata_com.png) [http://dev.socrata.com](http://dev.socrata.com)
## Get Support ![Get Support](../../img/Question.tif.png) [http://support.socrata.com](http://support.socrata.com)
## Contact Me [chris.metcalf@socrata.com](mailto:chris.metcalf@socrata.com) [support@socrata.com](mailto:support@socrata.com) [@chrismetcalf](http://twitter.com/chrismetcalf) ![Reach Out!](../../img/Speaker.tif.png)
# Questions? ![Questions?](../../img/Question.tif.png)
# Thanks! ![Moustaches!](../../img/moustaches.jpg)
## Powered by # [reveal.js](http://lab.hakim.se/reveal-js/)

Print Me!