Skip to content

Instantly share code, notes, and snippets.

@chrismetcalf
Last active December 14, 2015 02:58
Show Gist options
  • Save chrismetcalf/5017049 to your computer and use it in GitHub Desktop.
Save chrismetcalf/5017049 to your computer and use it in GitHub Desktop.

Open Data Day / Govathon / Code Across NYC Tips & Tricks

Handy Tools & Resources

Getting Started

I recommend starting with our getting started guide. It provides some background on locating API endpoints, performing basic queries, and Socrata datatypes.

Getting Help

I'll be hanging out online in several locations if you need help:

  • IRC: #socrata-soda on Freenode
  • @chrismetcalf or @socrata on Twitter
  • You can also email support@socrata.com as well to create a support ticket

If you're at Govathon, Code Across NYC, or the Seattle Open Data Day event, you can also locate a Socrata helper in person.

Tips

RESTful Resources

  • Accessed using RESTful paradigms
  • Use standard HTTP verbs (GET, POST, PUT, DELETE)

API Endpoints

Format:

/resource/[4-4].ext

Example: Alameda County Restaurant Inspections

https://data.acgov.org/Government/Alameda-County-Restaurants-Inspections/3d5b-2rnz 

... becomes ...

 https://data.acgov.org/resource/3d5b-2rnz.json 

Simple Queries

Equality queries (resource_code == "G") are just GET parameters:

 GET https://data.acgov.org/resource/3d5b-2rnz.json?resource_code=G 

SoQL Queries

More complex queries can be performed using SoQL, our query language:


GET https://data.acgov.org/resource/3d5b-2rnz.json?
$where=activity_date > '2012-11-01'

Customizing output

Tailor payload and retrieve XML:


GET https://data.acgov.org/resource/3d5b-2rnz.xml?
  $where=activity_date > '2012-11-01'
  &$select=activity_date,resource_code,violation_description

<response>
  <row>
  <row _id="20">
    <activity_date>2012-11-06T00:00:00</activity_date>
    <resource_code>G</resource_code>
    <violation_description>...</violation_description>
  </row>
...

Paging & limits

Control how much output you get:


  GET https://data.acgov.org/resource/3d5b-2rnz.json?
    $limit=1

Page through data:


  GET https://data.acgov.org/resource/3d5b-2rnz.json?
    $limit=25
    &$offset=50

Examples

Using JSONP (for cross-domain JavaScript)

Use the $jsonp parameter to set your callback function name:

http://data.acgov.org/resource/k9se-aps6.json?city=Alameda&$jsonp=jsonp_callback_name

From jQuery:


$.ajax({
  url: "http://data.acgov.org/resource/k9se-aps6.json?city=Alameda",
  jsonp: "$jsonp",
  dataType: "jsonp"
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment