Can you provide details on how to retrieve the cloud endpoint within an App?
It seems that getApiServerUrl() and apiServerUrl("some/path") are both available and return a string: https://cloud.hubitat.com/api (and https://cloud.hubitat.com/api/some/path respectively)
@patrick’s example in the Mobile App thread seemed to expose HTTP endpoints, but it wasn’t clear to me what the right URL structure was for these endpoints or how to access them?
I also saw mention of access tokens. It seems that the standard createAccessToken() and state.accessToken features are there… I assume these are used in the standard ways and suppose I can try it / test it once I understand what the URL structure is.
Similarly is there a method for determining the local HTTP endpoint for a SmartApp?
For the cloud endpoint you can use something like this to build the url:
"${getApiServerUrl()}/${hubUID}/apps/${app.id}/<PATH>?access_token=${state.accessToken}"
just replace <PATH> with the endpoint you are trying to hit.
For the local enpoint , we are going to add a method for this, but right now you can access it like this:
http://<HUB IP>/apps/api/<APP ID>/<PATH>?access_token=<ACCESS TOKEN>
just replace the <> values with the ones that match your Hub and App
This looks like just what I need. Where do I get the App ID? Is that the same as the OAUTH ClientID? I guess I'll have to browse over to @patrick 's mobile app thread.
well… i still don’t quite get it. I can’t see the log from the app so how do i get app.id
I’m calling from a php script.
Edit never mind. I think I have it figured out. I Can just make a http post from groovy app to my php app and save it over there in a cookie or session variable. Unless anyone know of an easier way? Also with both now local on the same network I can subscribe to events and post changes instead of JavaScript polling I had to do in ST.
from the app and it will show up in the log window.
Otherwise in the UI from the main page, click on Apps, then click on the app you want to know the id of. The id will be in the address bar of your browser.
Progress… pulling the things from the HousePanel app in groovy on Hubitat and mixing successfully with those from SmartThings… I am writing the panel to read from both systems so they can co-exist into the same HousePanel instance since most people will migrate gradually.
where curl_call is a simple function call to invoke curl in PHP. I grabbed the id and access_token from a log and stored it in a PHP constant. In the future I will use a post function to send it over to the code. I think this is how AT works. That way a user will only need to enter the URL of their HP installation.
Just a quick tip on how to dynamically build a local endpoint in an App. Just replace the <YOUR_PATH_HERE> with your app’s path. The only change I made to what was posted earlier in this thread is a method to retrieve the hub’s local IP address on the fly.
Which Hubitat firmware version are you currently running? I believe version .678 has some additional helper functions for generating OAUTH endpoint strings which make this even easier. I just learned of them from Josh (@josh). My hub did update successfully to .678 before it was pulled due to a few users having issues with the update process.
If you have .678, you may want to give these a try:
I’m not sure —- not home right now but will check. I’m calling Hubitat from PHP so I have to use authorization bearer header calls for the access token. Rest should work fine. Thanks for the tip.
Sorry about resurrecting such an old thread, but I am looking for how to properly get the access_token and endpoiint using OAUTH2 flow. I have been using the methods described here and I now understand that OAUTH2 flow is fully implemented and returns this information if one has a client_id and a client_secret just like it works on SmartThings. Do I have this right? If so can someone advise if the calls are the same with cloud.hubitat as the url to use to make the oauth calls?
Which app? If it's a custom app, then yes, you would do it within the app itself.
Something like:
if(!state.accessToken){
createAccessToken() //be sure to enable OAuth in the app settings or this call will fail
}
def localUri = getFullLocalApiServerUrl("optional/path") + "/?access_token=${state.accessToken}"