Search code examples
asp.net-mvcsocratasoda

How to set SODA API end points programatically in asp.net MVC


I am developing an application with open data hosted by socrata using the information from the below link http://dev.socrata.com/consumers/examples/creating-an-application-with-asp-dotnet.html How ever you need to specify the API end point in the code.

private const string _APIEndPoint4x4 = “4tka-6guv”;

Suppose there are 5000 records in the data set, it will list all the data in your applications. But you can change the end point by filtering this data by login in to socrata and saving it. For example we can filter the data say with year 2015 which will give us 100 records. When next time you run the application it will show only 100 records(We dont need to change API end point in code). I have gone through Soql query methods in Socrata which say you can set the api end points with conditions like this

https://soda.demo.socrata.com/resource/4tka-6guv?$where=magnitude > 3.0

My question is how can i use this in my application? I tried

private const string _APIEndPoint4x4 = "4tka-6guv?$where=magnitude > 3.0”;

But it gives the following error

The provided resourceId is not a valid Socrata (4x4) resource identifier.


Solution

  • As a follow up to the other answers...

    Each dataset has a resource identifier associated with it, also known as the Socrata 4x4. In your example, the resource identifier is 4tka-6guv. It is always 4 alphanumeric characters, a dash, and then 4 more alphanumeric characters. Hence the name Socrata 4x4

    The error message:

    The provided resourceId is not a valid Socrata (4x4) resource identifier.

    Indicates that the resourceId you provided in code is not in the correct format. This line:

    private const string _APIEndPoint4x4 = "4tka-6guv?$where=magnitude > 3.0”;
    

    is providing more than just the Socrata 4x4 - you have a query parameter in there as well ($where=magnitude > 3.0).

    Now, getting a reference to the dataset in Socrata, a la

    var dataset = client.GetResource<MyClass>("4tka-6guv");
    

    requires using only the Socrata 4x4.

    This does not download all the rows, but merely provides you with an object to execute additional queries against. To actually get some data, build up a SoqlQuery object to pass into the Query method on the dataset reference you got earlier.

    This is what Adrian Laurenzi (by way of the SODA.NET README) is showing.