Help using GetRouteSummaryForStop API

111 views
Skip to first unread message

Makaveli

unread,
May 15, 2012, 10:27:02 PM5/15/12
to Open Data Ottawa / OC Tranpo GPS API
I have not been able to get a response from this REST API. When I
submit the following query string:

https://api.octranspo1.com/v1.1/GetRouteSummaryForStop?appID=myApplicationID&apiKey=myAPIKey&stopNo=7659

I get:

Error: application with id="" was not found

What am I missing?

TIA.

Larry Dunkelman

unread,
May 15, 2012, 11:17:09 PM5/15/12
to open-data-ottawa-...@googlegroups.com
You can't submit the api call in your browser. You'll need to use 'curl'. 

Download cURL for Windows from here . Select  Win32 - Generic

Good luck.

Makaveli

unread,
May 16, 2012, 7:37:09 AM5/16/12
to Open Data Ottawa / OC Tranpo GPS API
Larry, thanks for the response. Guess I have more reading to do and
this may be a silly question but why the dependency on curl? Is this
API not a simple REST/JSON API that I can issue HTTP GET/POST requests
to? I plan on using this with Ajax.



On May 15, 11:17 pm, Larry Dunkelman <larry.dunkel...@gmail.com>
wrote:
> You can't submit the api call in your browser. You'll need to use 'curl'.
>
> Download cURL for Windows from *here* <http://curl.haxx.se/download.html> .
> Select  *Win32 - Generic*
>
> Good luck.
>
>
>
>
>
>
>
> On Tue, May 15, 2012 at 10:27 PM, Makaveli <klaus....@gmail.com> wrote:
> > I have not been able to get a response from this REST API.  When I
> > submit the following query string:
>
> >https://api.octranspo1.com/v1.1/GetRouteSummaryForStop?appID=myApplic...

Don Kelly

unread,
May 16, 2012, 8:26:11 AM5/16/12
to open-data-ottawa-...@googlegroups.com
The issue you're having is a little more complicated than just using
curl to make the request. HTTP requests can be made with a few
different "verbs" denoting what you're trying to accomplish. In REST
(http://en.wikipedia.org/wiki/Representational_state_transfer) terms,
they are:

- GET: retrieving someting
- POST: creating something
- PUT: updating something
- DELETE: destroying something

The live REST api is actually POST-driven. Your browser is making a GET request.

Further, even if you change your code from GET to POST, the URL you've
posted still won't work. This particular REST api requires that you
place the parameters in the POST data of the request. You can do this
with curl using the -d option:

curl -d "appID={appID}&apiKey={apiKey}&stopNo=7659"
https://api.octranspo1.com/v1.1/GetRouteSummaryForStop

For the actual code you're writing, you'll need to refer to the docs
for your HTTP client library to figure out how to pass POST data.

Don/
--
http://hi.im/donkelly
https://github.com/karfai

Makaveli

unread,
May 16, 2012, 8:31:34 AM5/16/12
to Open Data Ottawa / OC Tranpo GPS API
Thanks for detailed response Don. I have sorted this out.

On May 16, 8:26 am, Don Kelly <kar...@gmail.com> wrote:
> The issue you're having is a little more complicated than just using
> curl to make the request. HTTP requests can be made with a few
> different "verbs" denoting what you're trying to accomplish. In REST
> (http://en.wikipedia.org/wiki/Representational_state_transfer) terms,
> they are:
>
> - GET: retrieving someting
> - POST: creating something
> - PUT: updating something
> - DELETE: destroying something
>
> The live REST api is actually POST-driven. Your browser is making a GET request.
>
> Further, even if you change your code from GET to POST, the URL you've
> posted still won't work. This particular REST api requires that you
> place the parameters in the POST data of the request. You can do this
> with curl using the -d option:
>
> curl -d "appID={appID}&apiKey={apiKey}&stopNo=7659"https://api.octranspo1.com/v1.1/GetRouteSummaryForStop
>
> For the actual code you're writing, you'll need to refer to the docs
> for your HTTP client library to figure out how to pass POST data.
>
> Don/
>
> On Tue, May 15, 2012 at 10:27 PM, Makaveli <klaus....@gmail.com> wrote:
> > I have not been able to get a response from this REST API.  When I
> > submit the following query string:
>
> >https://api.octranspo1.com/v1.1/GetRouteSummaryForStop?appID=myApplic...

Mark Morin

unread,
Jan 30, 2013, 9:48:00 AM1/30/13
to open-data-ottawa-...@googlegroups.com
Hello Makaveli,

I am curious as to how you sorted this out. Are you using Java? I am experimenting with this API using Java, and am able to do an HTTP POST using Apache and get the response back as a XML String. I have run into problems unmarshaling the SOAP response into Java objects. When I try SOAP libraries (like Apache Axis2), they assume the POST request is a SOAP request as well, and according to the API it is not. The POST request is not understood as a result.

Any suggestions you (or anyone) may have would be appreciated.

Thanks,
Mark

Makaveli

unread,
Jan 30, 2013, 10:04:03 PM1/30/13
to open-data-ottawa-...@googlegroups.com
Mark,
These are not SOAP Webservices which is why Axis2 is failing. They are somewhat RESTFul in the sense that you will have to submit a query string to the webservice and return a string, which you then parse accordingly. For example, this is what I am doing in C# to get NextTripForStops:
public override object GetVehiclesProgressForStop(string agency, string routeID, string stopID)
{
if (string.IsNullOrWhiteSpace(routeID) || string.IsNullOrWhiteSpace(stopID)) return null;

var request = (HttpWebRequest)WebRequest.Create("https://api.octranspo1.com/v1.1/GetNextTripsForStop");
request.Method = "POST";

var parameters = GenerateQueryString("appID", "myAppId", "apiKey",
"myApiKey", "routeNo", routeID, "stopNo", stopID);
parameters += "&submit=submit";

var encoding = System.Text.Encoding.UTF8;
byte[] data = encoding.GetBytes(parameters);

request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";

using (var streamWriter = request.GetRequestStream())
{
streamWriter.Write(data, 0, data.Length);
streamWriter.Close();
}

// get the response
string tracksString = null;
var response = (HttpWebResponse)request.GetResponse();

using (var reader = new StreamReader(response.GetResponseStream(), encoding))
{
tracksString = reader.ReadToEnd();
reader.Close();
}

return ConvertStopMonitoringToPidacFormat(tracksString);
}
and my parsing logic uses .NET API to convert the string to objects. As you can see, I am manually creating a query string and parsing the string result in return. The same will apply to all other APIs exposed by the service.
Hope this helps.
Klaus.
Reply all
Reply to author
Forward
0 new messages