2

I use a very cool Google Script I found on Github (source: https://gist.github.com/beezly/9b2de3749d687fdbff3f) to fetch the temperature on my Nest thermostat and log it into a Google Spreadsheet.

It is working great when I run the script manually, but not when I use a time trigger to run it automatically.

When posting the credential to the API on this line:

Line 12: var response = JSON.parse(UrlFetchApp.fetch('https://home.nest.com/user/login', options).getContentText());

The exception raised is:

Request failed for https://home.nest.com/user/login returned code 429. Truncated server response: Too many requests (use muteHttpExceptions option to examine full response) (line 12, file "Code")

I suspect that I'm not the only one using the script, and the Google source IP used by the trigger has exceeded the limit of the Nest API.

Would you have any solution for me? I have considered using a Proxy server, but the UrlFetchApp.fetch function does not seem to accept it.

Thank you,

PF

Rubén
  • 34,714
  • 9
  • 70
  • 166
pfc
  • 90
  • 1
  • 9
  • Change the option object as below. This should give you the full returned error from the nest api. var options = { "method" : "post", "payload" : payload, "muteHttpExceptions":"true" }; – Spencer Easton Feb 10 '15 at 15:08
  • I did the change, but it still gives me the same error (which, to be honest, is already quite explicit) – pfc Feb 10 '15 at 16:43
  • Hopefully this blog post would help you https://community.nest.com/message/43271 – KRR Feb 10 '15 at 17:55
  • Nest has two types of rate limits: Per Device/Structure and by Access Token. [Nest Documentation - Rate Limits](https://developer.nest.com/documentation/cloud/data-rate-limits) The "Device" is your thermostat I think. The Access Token doesn't have anything to do with the Google Server, I don't think. It Nest is monitoring something like the IP Address of the sender, then someone on their end should be able to adjust the rate limit for that. Google can't fix that. Maybe contact Nest? The code works manually, so the syntax must be right. – Alan Wells Feb 10 '15 at 23:24
  • When you run the code manually, to you somehow enter a password and email? Is that hard coded into your script? – Alan Wells Feb 10 '15 at 23:26
  • @ krr Thx a lot. But at the very end of the thread, they say that they actually have exactly the same problem as I have. @ sandy-good Good idea, I will contact Nest. Yes, my email and password is harcoded into the script code. – pfc Feb 11 '15 at 10:17
  • I am seeing the same problem. The https://home.nest.com/user/login works from curl from my local machine, but it doesn't work from apps script. I suspect, as @SandyGood suggests, that they are rate limiting by IP. So the Google's outgoing IPs are all blocked. I suspect Nest wants us to be using developer keys instead which have their own rate limit. – studgeek Jul 22 '17 at 22:03

1 Answers1

1

I only ran into the "Too many requests" error during development when I was testing that same script. I was able to get this function to run hourly no problem, even every 5 minutes.

To get this script run as expected on a trigger just switch the getData() to a doGet(), publish it as a web app with anonymous access then create another function (i called it getData()) that makes a request to your published web app url (which invokes a doGet()), then just create your time-based trigger to run the new getData().

here's my version https://gist.github.com/jbutters/bece2fffe85080fe4314

jbutters
  • 48
  • 4
  • Thx a lot for your response. I tried your code, it does work when I run the doGet() function form the script editor. It does not work when I run the getData() (does nothing). When I publish the app, and call the app URL, I receive the error "Request failed for https://home.nest.com/user/login returned code 400. Truncated server response: {"error":"access_denied","error_description":"invalid user credentials"} (use muteHttpExceptions option to examine full response)". Seems quite curious, since as I said, doGet() works well from the script editor. Any idea? – pfc Apr 09 '15 at 08:41
  • try saving a new version then publish that new version, the link should stay the same but double check or test with the 'latest code' /dev link in your logged in browser session (the 'latest code' /dev link will not work with the timebased trigger) – jbutters Apr 09 '15 at 14:03
  • 'latest code' /dev link works... but I need to be logged in to use it. The official web app URL is still returning the same error 400, but I don't need to be logged in to use it. – pfc Apr 13 '15 at 10:36
  • since 'latest code' works, did you try saving a new version of the project then, the publish that new version with: Execute the app as: me (your google account) and Who has access to the app: Anyone, even anonymous – jbutters Apr 13 '15 at 13:53
  • yeah, now it works, indeed, I didn't get correctly what you meant with "new version" at the beginning, sorry for that. Thx a lot !! – pfc Apr 19 '15 at 14:02