Advertisement
Guest User

Nest API batch test commands

a guest
Feb 19th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. @echo off
  2.  
  3. set curl_path=c:\nest\curl
  4. set client_pin=[you get this from the provided URL on the client page]
  5. set client_id=[you get this from the client page]
  6. set client_secret=[you get this from the client page]
  7. set access_token=[you'll get this from a successful oauth]
  8.  
  9. rem set new_url=https://firebase-apiserver02-tah01-iad01.dapi.production.nest.com:9553
  10.  
  11. rem TOGGLE FOR AUTH
  12. rem set GET_AUTH=true
  13. rem TOGGLE FOR AUTH
  14.  
  15. rem TOGGLE FOR DEAUTH
  16. set GET_DEAUTH=true
  17. rem TOGGLE FOR DEAUTH
  18.  
  19. rem TOGGLE FOR GET
  20. rem set GET_DATA=true
  21. rem TOGGLE FOR GET
  22.  
  23. rem TOGGLE FOR SET
  24. rem set SET_DATA=true
  25. rem TOGGLE FOR SET
  26.  
  27. rem TOGGLE FOR STREAM
  28. rem set STREAM_DATA=true
  29. rem TOGGLE FOR STREAM
  30.  
  31. rem DEVICE_CONFIG
  32. rem virtual:
  33. set dev_id1=[manually enter example devid]
  34. rem real:
  35. set dev_id2=
  36.  
  37. set dev_id=%dev_id1%
  38. rem DEVICE_CONFIG_END
  39.  
  40. rem VALUE_CONFIG
  41. set value1=target_temperature_f
  42. set value2=name
  43. set value3=hvac_mode
  44. set value4=ambient_temperature_f
  45. set value5=target_temperature_high_f
  46.  
  47. set value_name=%value3%
  48.  
  49. set new_int_value=77
  50. set new_string_value=heat
  51.  
  52. set new_value=%new_string_value%
  53. rem VALUE_CONFIG_END
  54.  
  55. rem STRUCT_CONFIG
  56. set struct1=devices
  57. set struct2=structures
  58. set struct3=metadata
  59. set struct4=devices/thermostats
  60. set struct4=devices/smoke_co_alarms
  61. set struct4=devices/company
  62.  
  63. set struct_name=%struct2%
  64. rem STRUCT_CONFIG_END
  65.  
  66.  
  67. set url=https://developer-api.nest.com/%struct_name%.json?auth=%access_token%
  68. set url_by_id=%new_url%/devices/thermostats/%dev_id%.json?auth=%access_token%
  69. set url_by_value=%new_url%/devices/thermostats/%dev_id%/%value_name%.json?auth=%access_token%
  70.  
  71. set header=Content-Type: application/json
  72.  
  73. rem GET_DATA
  74. set get_struct=curl\curl.exe -k -L %url%
  75. set get_by_id=curl\curl.exe -k -L %url_by_id%
  76. set get_by_value=curl\curl.exe -k -L %url_by_value%
  77.  
  78. set get_url=%get_by_id%
  79. rem GET_DATA_END
  80.  
  81. rem OAUTH
  82. rem set oauth=curl\curl.exe -k -i -v -X POST -d "code=%client_pin%&client_id=%client_id%&client_secret=%client_secret%&grant_type=authorization_code" https://api.home.nest.com/oauth2/access_token
  83.  
  84. set oauth=curl\curl.exe -k -i -v -X POST "https://api.home.nest.com/oauth2/access_token?code=%client_pin%&client_id=%client_id%&client_secret=%client_secret%&grant_type=authorization_code"
  85.  
  86. rem SET_DATA
  87. rem set change_num=curl\curl.exe -k -i -L -X PUT %url_by_value% -H "Content-Type: application/json; charset=UTF-8" -d "%new_int_value%"
  88.  
  89. rem set change_text=curl\curl.exe -k -i -L -X PUT "%url_by_value%" -H "%header%" -d '"%new_string_value%"'
  90. rem set change_text=curl\curl.exe -k -i -L -X PUT -H "Content-Type: application/json; charset=UTF-8" -d "{"%value_name%":%new_value%}" %url_by_id%
  91.  
  92. rem set change_text=curl\curl.exe -k -i -L -X PUT "%url_by_value%" -H "%header%" -d '"%new_value%"'
  93.  
  94. rem THIS WORKS:
  95. rem set change_text=curl\curl.exe -k -L -X PUT "https://developer-api.nest.com/devices/thermostats/%dev_id%?auth=%access_token%" -H "Content-Type: application/json" -d "{\"hvac_mode\":\"heat\"}"
  96.  
  97. rem set stream=curl\curl.exe -k -i -v -L -X GET -H "Accept: application/json" -H "Accept: text/event-stream" -H "Keep-Alive: 60" -H "Connection: keep-alive" "https://firebase-apiserver02-tah01-iad01.dapi.production.nest.com:9553/?auth=[FILL IN AUTH_TOKEN]"
  98.  
  99. set deauth=curl\curl.exe -k -i -v -L -X DELETE "https://api.home.nest.com/oauth2/access_tokens/%access_token%"
  100.  
  101. set set_data=%change_text%
  102.  
  103. echo.
  104.  
  105. if defined GET_AUTH %oauth%
  106. if defined GET_AUTH echo.
  107.  
  108. if defined GET_DEAUTH %deauth%
  109. if defined GET_DEAUTH echo.
  110.  
  111. if defined GET_DATA echo %get_url%
  112. if defined GET_DATA echo.
  113. if defined GET_DATA %get_url%
  114. if defined GET_DATA echo.
  115.  
  116. if defined SET_DATA echo %set_data%
  117. if defined SET_DATA echo.
  118. if defined SET_DATA %set_data%
  119. if defined SET_DATA echo.
  120.  
  121. if defined STREAM_DATA %stream%
  122. if defined STREAM_DATA echo.
  123.  
  124. goto end_com
  125.  
  126. - To **change** the specific structure to away. The value here is a string so be sure to include the single quotes:
  127.  
  128. curl -v -L -X PUT "https://developer-api.nest.com/structures/<STRUCTURE ID>/away?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '"away"'
  129.  
  130. :end_com
  131.  
  132. goto end_com2
  133.  
  134. echo %curl_path%
  135. echo %client_pin%
  136. echo %client_id%
  137. echo %client_secret%
  138. echo %access_token%
  139.  
  140. :end_com2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement