Home

Welcome! Log in or Join us

Forums The Open Grid API Problems

Subscribe to API Problems 11 posts, 2 voices , Tagged: API

Reply to topic
 

 
Drich-paris_med_medium
Aug 1, 2013 4:43pm
6 posts

Now that I have my GEM talking to SEG, I would like to pull the data back to my own servers so I can do some processing and graphing at home. However, I can't get the API to give me any data, is there something up with it?

Here is what I am trying from my server at home (with my API key removed):

> curl http://api.smartenergygroups.com/api_streams/<apikey>.xml

  (status error 'unknown')

I've tried a couple of different utils, but I alwasy get the status error of unknown. If I try connecting directly to the server, I see that I am getting a 301 redirect from api.smartenergygroups.com -- is something up with the API server?

> telnet api.smartenergygroups.com 80
Trying 80.77.87.119...
Connected to api.smartenergygroups.com.
Escape character is '^]'.
GET /api_streams/<apikey>.xml HTTP/1.0

HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.19
Date: Thu, 01 Aug 2013 16:39:45 GMT
Content-Type: text/html
Content-Length: 185
Connection: close
Location: http://smartenergygroups.com/api_streams/&lt;ap...

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.1.19</center>
</body>
</html>

X
> telnet api.smartenergygroups.com 80
Trying 80.77.87.119...
Connected to api.smartenergygroups.com.
Escape character is '^]'.
GET /api_streams/a60fb1e8e60ec0e.xml HTTP/1.0

HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.19
Date: Thu, 01 Aug 2013 16:39:45 GMT
Content-Type: text/html
Content-Length: 185
Connection: close
Location: http://smartenergygroups.com/api_streams/a60fb1...

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.1.19</center>
</body>
</html>

 
Drich-paris_med_medium
Aug 1, 2013 11:27pm
6 posts

In playing around a bit, I think I see at least part of my problem. The individual stream API calls seem to work, for example I can get my main power feed by using the stream URL for just that stream. The device list works as well. I I think my initial problem was that I was trying to use the site token with the streams URLs.

The only thing I can't get to work is the main site API URL, it is returning a 500:

> curl http://api.smartenergygroups.com/sites/&lt;site...
(error server_fail 500)

I would think I could call that one in order to get the device list, the get the individual streams from there.

 
Samotage_300_medium
Aug 2, 2013 3:35am
555 posts

Hey sjthespian,

A GET requst to the API will give fail, as it needs a PUT request, with the S-Expression in the body.

api.smartenergygroups.com/sites<token here> 

is the new verison, more restful.

Some thoughts are on the blackboard for a simple GET type, however this isn't very RESTful... and the parameter would need to be urlencoded to excape the spaces etc.

You can test out your S-Expressions by going to 

https://smartenergygroups.com/tools/api_traces

Or use another third party API tester.

Let me know how you get on!

Sam, @samotage

 
Drich-paris_med_medium
Aug 2, 2013 3:43pm
6 posts

Sam,

Even for querying data? I'm getting results just fine for all of the stream and device requests with GET, in fact, PUT fails when I try and use it for those as well as the sites URL. I'm using the docs from here:

  http://smartenergygroups.com/api

in the Stream Data section and getting the URLs from my "All my keys:" page. Since those docs show query_string values, I was assuming GET requests, and those work fine for my devices so far (although it seems to ignore point_limit, never returning more than about 50 data points.

Here's some examples:

> curl -s -q http://api.smartenergygroups.com/api_devices/xx... | wc -l
     327
> curl -X PUT -H "Content-length: 0" -s -q http://api.smartenergygroups.com/api_devices/xx... | wc -l
       0
> curl -X PUT -H "Content-length: 0" -s -q http://api.smartenergygroups.com/api_devices/xx...
(error server_fail 400)

Requests to "http://api.smartenergygroups.com/sites/xxxxxxxx.xml" always fail.

 

 
Samotage_300_medium
Aug 3, 2013 2:21am
555 posts

Oooh... that's embarrasing...

Thanks for the heads up, there was a little bug after the cutover to a new server recently.

I've reworked the streams, devices and sites API's to work better for the GET which should be used to get data, PUT is for update, as per normal HTTP verbs.  DELETE and POST are not supported by the API as of now.

Try again with some of the links in

https://smartenergygroups.com/my_things/show_keys

And you should GET win ;)

Sam, @samotage

 
Drich-paris_med_medium
Aug 4, 2013 1:45am
6 posts

Thanks Sam, that did the trick! I can now query my site_token URL and get a list of all of my devices and streams. It looks like that also fixed my problems using point_limit, it's returning the number of points I request.

Since that was so easy, you want to fix my code so it updates the RRD files on my server? :-) (I've used RRDs many many times, but for some reason it is updating the last updated time but not the data).

 
Samotage_300_medium
Aug 4, 2013 3:08am
555 posts

Thanks for reporting the API problem!

Can't help you with your RRD software, though SEG should make them redundant ;)

Sam, @samotage

 
Drich-paris_med_medium
Aug 7, 2013 8:47pm
6 posts

I had some time to work on this earlier today, and now I've run into a new problem with formerly working code. It looks like the server isn't accepting start_date_time on stream urls. For example, the following gives me a server error:

http://api.smartenergygroups.com/streams/xxxxxx... 13:37:43 -0700

However, if I remove the start_date_time parameter it works and gives me the last 100 data points.

Any idea what might have changed? As I said, this is code that was working fine when I last tried it on the 3rd...

 
Samotage_300_medium
Aug 8, 2013 1:48am
555 posts

Hey sjthespian,

You will need to give it a date as well as a time :D

Also, most browsers wil url encode the query parameters, however this may need to be done programatically is calling the api via some code.

If pain persists email me the url you are having trouble with at sam at this domain and I can look into it.

Thanks!

Sam.

 
Drich-paris_med_medium
Aug 8, 2013 2:00pm
6 posts

Sam,

I'll drop you an e-mail, as the date is in that URL, the forum software is truncating it when it display it. It doesn't seem to matter if it is URL encoded or not, I still get a 500.

This is code that I haven't touched that was working fine a week ago, I only noticed it when I started rewriting it in python to try and fix my rrd problems.

 
Samotage_300_medium
Aug 10, 2013 1:38am
555 posts

Hey Daniel,

I took a look and found some fail on the date parse for the new api.  Try it again, I got all your mail examples  to work as expected!

Let me know if the pain persists!

Thanks,

Sam.

Log in to reply to this topic

Forums The Open Grid API Problems

copyright © 2008 Smart Energy Groups pty ltd