API Documentation
Get Started with the Oil Reporter API

What is the Oil Reporter API?

The Oil Reporter API contains a series of methods for obtaining data through standard HTTP requests. This allows Oil Reporter to be integrated with just about any application that can connect to the web.

Sign Up

You can get an API key by signing up for one here.

Table of Contents

Data Structure

The structure of a report is below.

- id (integer, read-only)
- organization_pin (integer, optional)
- report_session_id (integer, optional)
- oil (integer, 0-10)
- wetlands (integer, 0-10)
- description (text)
- wildlife (text)
- latitude (float)
- longitude (float)
- created_at (datetime)
- media (hash/binary) 
    When parsing the results of a call to list, the media property 
    is a hash with the fields tiny, thumb and medium each of which 
    is a string corresponding to the URL where the image is located.

    If media has not been set then the value is null.

    On a call to update to upload a photo, then media accepts a binary stream.
- meta (string key value pair)
    Can only create this when updating a report or adding media.
    See documentation below for a good explanation on how to add metdata.

Create a New Report

Allows you to create a new report. This request needs a unique device identifier (device_id).

  • Method: POST
  • URL: /reports
  • Required: oil, wetlands, device_id, api_key
  • Success: id returned and HTTP status code 200
  • Failure: array of errors and HTTP status code 422
  • curl -d "api_key=YOUR_API_KEY&latitude=29.964639&longitude=-90.067763&oil=5&wetlands=7&description=Distressed%20Wildlife&device_id=UNIQUE_DEVICE_ID" http://oilreporter.org/reports
    Returns {"id":8}
    

    Create a New Report Session

    Allows you to create a new report session to use to group a batch of reports.

  • Method: POST
  • URL: /report_sessions
  • Required: api_key
  • Success: id returned and HTTP status code 200
  • Failure: array of errors and HTTP status code 422
  • curl -d "api_key=YOUR_API_KEY" http://oilreporter.org/report_sessions
    Returns {"id":26}
    

    Add Metadata to Report Session

    Allows you to add as many metadata elements to your report session. You need the ID of the report you created to be able to call this url. Meta parameters can use any key and any value. Both keys and values are stored as strings. You can pass as many metadata items as you want. In the example below we are adding two meta values. The first one has a key of my_key_1 with a value of custom value. The other meta element has a key of extra_url with a value of oilreporter.org.

  • Method: PUT
  • URL: /report_sessions/*ID*
  • Required: id, api_key, meta
  • Success: empty text and HTTP status code 200
  • Failure: empty text and HTTP status code 422
  • curl -d "api_key=YOUR_API_KEY&meta[my_key_1]=custom%20value&meta[extra_url]=oilreporter.org" -X PUT http://oilreporter.org/report_sesions/8
    Returns empty text and an HTTP status code of 200
    

    Add Metadata to Reports

    Allows you to add as many metadata elements to your report. You need the ID of the report you created to be able to call this url. Meta parameters can use any key and any value. Both keys and values are stored as strings. You can pass as many metadata items as you want. In the example below we are adding two meta values. The first one has a key of my_key_1 with a value of custom value. The other meta element has a key of extra_url with a value of oilreporter.org.

  • Method: PUT
  • URL: /reports/*ID*
  • Required: id, api_key, meta
  • Success: empty text and HTTP status code 200
  • Failure: empty text and HTTP status code 422
  • curl -d "api_key=YOUR_API_KEY&meta[my_key_1]=custom%20value&meta[extra_url]=oilreporter.org" -X PUT http://oilreporter.org/reports/8
    Returns empty text and an HTTP status code of 200
    

    Add Media to Report

    Allows you to add media to an existing report. You need the ID of the report you created to be able to call this url. You may also pass metadata in this call as well (see above).

  • Method: PUT
  • URL: /reports/*ID*
  • Required: id, api_key
  • Success: empty text and HTTP status code 200
  • Failure: empty text and HTTP status code 422
  • curl -X PUT -F "media=@seagull.jpg" http://oilreporter.org/reports/8?api_key=YOUR_API_KEY
    Returns empty text and an HTTP status code of 200
    

    Retrieve a List of Reports

    Allows you to retrieve a list of reports.

  • Method: GET
  • URL: /reports.format (format: json, xml)
  • Required: api_key
  • Optional: page (default: 1)
  • Success: array of paginated results status code 200
  • curl http://oilreporter.org/reports.json?api_key=YOUR_API_KEY
    Returns
    [
      { "id": 8,
        "oil": 5,
        "wetlands": 7,
        "description": "Distressed Wildlife",
        "wildlife": "Dead",
        "latitude":"29.9646",
        "longitude": "-90.0678",
        "created_at": "2010-05-13T19:29:54Z",
        "report_session_id": null,
        "media": { "tiny":"http://s3.amazonaws.com/oilreporter_production/medias/7/tiny.jpg?1273722135",
                   "thumb":"http://s3.amazonaws.com/oilreporter_production/medias/7/thumb.jpg?1273722135",
                   "medium":"http://s3.amazonaws.com/oilreporter_production/medias/7/medium.jpg?1273722135" },
        "meta": { "my_custom_key": "my custom value",
                  "another_item": "another value"}
      }
    ]
    

    Retrieve a List of Reports by Report Session

    Allows you to retrieve a list of reports with a specific report session id

  • Method: GET
  • URL: /report_sessions/REPORT_SESSION_ID/reports.format (format: json, xml)
  • Required: api_key, report_session_id
  • Optional: page (default: 1)
  • Success: array of paginated results status code 200
  • curl http://oilreporter.org/report_sessions/REPORT_SESSION_ID/reports.json?api_key=YOUR_API_KEY
    Returns
    [
      { "id": 8,
        "oil": 5,
        "wetlands": 7,
        "description": "Distressed Wildlife",
        "wildlife": "Dead",
        "latitude":"29.9646",
        "longitude": "-90.0678",
        "created_at": "2010-05-13T19:29:54Z",
        "report_session_id": 26,
        "media": { "tiny":"http://s3.amazonaws.com/oilreporter_production/medias/7/tiny.jpg?1273722135",
                   "thumb":"http://s3.amazonaws.com/oilreporter_production/medias/7/thumb.jpg?1273722135",
                   "medium":"http://s3.amazonaws.com/oilreporter_production/medias/7/medium.jpg?1273722135" },
        "meta": { "my_custom_key": "my custom value",
                  "another_item": "another value"}
      }
    ]
    

    List reports by organization

    Allows you to retrieve a list of an organization's reports

  • Method: GET
  • URL: /organizations/*PIN*
  • Required: pin (Sign up), api_key
  • Optional: page (default: 1)
  • Success: List of reports and HTTP status code 200
  • Failure: Error message and HTTP status code 404
  • curl -d "api_key=YOUR_API_KEY" http://oilreporter.org/organizations/1001
    [
      { "id": 8,
        "oil": 5,
        "wetlands": 7,
        "description": "Distressed Wildlife",
        "wildlife": "Dead",
        "latitude":"29.9646",
        "longitude": "-90.0678",
        "created_at": "2010-05-13T19:29:54Z",
        "report_session_id": null,
        "media": { "tiny":"http://s3.amazonaws.com/oilreporter_production/medias/7/tiny.jpg?1273722135",
                   "thumb":"http://s3.amazonaws.com/oilreporter_production/medias/7/thumb.jpg?1273722135",
                   "medium":"http://s3.amazonaws.com/oilreporter_production/medias/7/medium.jpg?1273722135" },
        "meta": { "my_custom_key": "my custom value",
                 "another_item": "another value"}
      }
    ]