Updating data with soda-ruby

An Important Note

The ability to write to a Socrata dataset requires you to own that dataset or be granted permission to write to it. This might not apply to you. Unless you’re already a Socrata customer, you have a few other options:

Sign up for an account on opendata.socrata.com, our public portal where you can create a limited number of datasets for free.

Create Your Client and Authenticate

Once you have your account information and your application token, you can create your client. For this example, we’ll be updating the USGS Earthquake Reports dataset on our API demo domain, soda.demo.socrata.com. It has an identifier of 4tka-6guv:

Create Your Update Payload

We’re going to use the POST method to update our dataset, using the upsert functionality documented on the Socrata Developer Portal. If you’ve never used upsert before, make sure you have your primary key set properly to make sure you update records properly.

For this example, we’re going to create one record and update a second, but the record set could easily be thousands of records. The soda-ruby post method accepts an array of hashes to represent the records you want to update in your dataset. For this example, earthquake_id is the identifier for this dataset, and it is a String value: