Https://graph.api.smarthings.com Failed to load devices

5.5.1 is rockin the Casbah!

2 Likes

A fix is ready for SmartRules users in the UK now too. Unfortunately, our fix cannot roll out quite as quickly as SmartTiles, because we’ll have to wait for Apple approval. Anyone interested in helping us beta test, please send me a private message or email to support (at) obycode.com.

2 Likes

Hi, I saw this topic and it seems I have this problem. I’m not able to load devices for this smartapp: https://github.com/oehokie/SmartDSC/blob/master/smartapp/dscAlarmIntegrationSmarththingsApp.groovy .

I’m able to select the location when trying to authorize but “my devices” don’t show up. It doesn’t seem to be fixed…

@slagle Could you please help me out?

You’ll need to reach out to the developer that wrote that integration to see if they can get you sorted out.

The developer will need the information from this thread most likely:

I’m trying to use this URL:

https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=CLIENT_ID&scope=app&redirect_uri=http://localhost

Of course I’m replacing CLIENT_ID to the right OAuth Client ID…

Try this:

I tryed to use the URl you mention on your post 38:

//STEP 1 - Get Access Code
if(!isset($_REQUEST[‘code’]) && !isset($_REQUEST[‘access_token’]))
{
header( “Location: ${apiurl}/oauth/authorize?response_type=code&client_id=$client&scope=app&redirect_uri=”.$url );
}

I can see my location and select it, but afterwards It doesn’t show any of my devices that I want to authorize. When I click authorize, it gives me an error saying to contact support because probably I didn’t select any device (because I couldn’t).

This was the only app that is giving me this problem. I have added others in the past with no problem. This is really frustrating…

Could you please do a small test on your side and add this SmartApp (https://github.com/oehokie/SmartDSC/blob/master/smartapp/dscAlarmIntegrationSmarththingsApp.groovy) and try to give it access to your devices?

Thanks for any help!

Sure… I’ll give it a try later today.

If you are debugging, do the best you can to trim out all the extra Preferences Pages that aren’t critical to do an OAuth test. Perhaps copy the entire SmartApp, delete all logic except for basic device selection and mapping definition stub methods.

It is more than likely you are hitting a SmartThings bug (if you haven’t noticed, there are dozens of bugs), that, unfortunately, is impossible to determine how to isolate without tediously trying everything.

1 Like

Following your advice, I removed all the code and I created a simple example. It seems the problem is related to using the “pages”. I got an example from the smartthings tutorial. The following code works:

preferences {
section(“When activity on any of these sensors”) {

    input "contactSensors", "capability.contactSensor",
        title: "Open/close sensors", multiple: true
    input "motionSensors", "capability.motionSensor",
        title: "Motion sensors?", multiple: true
}
section("Turn on these lights") {
    input "switches", "capability.switch", multiple: true
}

}

The following code doesn’t work:

preferences {
page(name: “pageOne”, title: “When there’s activity on any of these sensors”, nextPage: “pageTwo”, uninstall: true) {
section(“Choose sensors to trigger the action”) {

        input "contactSensors", "capability.contactSensor",
            title: "Open/close sensors", multiple: true
        input "motionSensors", "capability.motionSensor",
            title: "Motion sensors?", multiple: true
    }
}
page(name: "pageTwo", title: "Turn on these lights", nextPage: "pageThree") {
    section {
        input "switches", "capability.switch", multiple: true
    }
}
page(name: "pageThree", title: "Name app and configure modes", install: true, uninstall: true) {
    section([mobileOnly:true]) {
        label title: "Assign a name", required: false
        mode title: "Set for specific mode(s)", required: false
    }
}

}

So it seems that for some inexplicably reason, I don’t have access to authorize my devices if there is any page available in the App. Is there anyone I can contact here in the forum about this?

Thanks for you help!

2 Likes

Your discovery sounds correct, actually.

Maybe you can put your main inputs on the primary preferences and reference additional pages using HREF. Sorry I don’t have an example available, but, if I find one I’ll post again here.

Regardless, you should still be able to authorize the SmartApp with 0 Devices (which will “install it” unconfigured) and then the user can use the SmartApp configuration / preference pages inside the mobile App to select Devices and other Preferences. This is how SmartTiles does it.

1 Like

I tried with HREF and it doesn’t work either. This is the example I used:

preferences {
page(name: “hrefPage”)
page(name: “deadEnd”)
}

def hrefPage() {
dynamicPage(name: “hrefPage”, title: “href example page”, uninstall: true) {
section(“page”) {
href(name: “href”,
title: “dead end page”,
required: false,
page: “deadEnd”)
}
}
}

def deadEnd() {
dynamicPage(name: “deadEnd”, title: “dead end page”) {
section(“dead end”) {
paragraph “this is a simple paragraph element.”
}
}
}

So I don’t know how to fix it…

@slagle Is this a known issue?

We’re working on docs that will discuss some differences in how SmartApp preferences work as part of the Authorization flow. Will update you soon.

3 Likes

Thanks for your answer. Would you be kind enough to share an ETA when this is going to be available?

http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/smartapp.html

And

http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/authorization.html

We will make an announcement today; we still need to doc how the preferences work with the auth page.

We also updated the example app found here: https://github.com/SmartThingsCommunity/Code/tree/master/smartapps/tutorials/web-services-smartapps

Regarding the preferences for the Authorization page, you can specify a page to be used in the authorization process using the oauthPage option to preferences:

preferences(oauthPage: "authorizeDevices") {
    page(name: "authorizeDevices", title: "", nextPage: "instructionPage", install: false, uninstall: true) {
        section("Select Devices to Authorize") {
            input "switches", "capability.switch", title: "Switches:"
            input "motions", "capability.motionSensor", title: "Motion Sensors:"
        }
    }
    page(name: "instructionPage", title: "Device Discovery", install: true) {
        section() {
            paragraph "Some instructional text"
        }
    }
}

Then the authorizeDevices page will be used on the Authorization page.

4 Likes

Yayyyyyyy! (yyyyyyyyy)!

Good to know, I will test this and report :slight_smile: Thanks!

1 Like

So it finally worked :slight_smile: Thanks! But I got stuck with this error below when trying to follow this tutorial at http://smartthings-documentation.readthedocs.org/en/latest/smartapp-web-services-developers-guide/implementation.html

{“error”:“invalid_request”,“error_description”:“Remote OAuth2 token request failed with code: 401, text: Unauthorized”}

I’m getting this error in the step:

Step 7: Obtain an access token using the grant.

Could you help me out?

So you’re saying this call below doesn’t work, despite following the preceding steps to get a valid “Code” parameter?

Request:
GET
https://graph.api.smartthings.com/oauth/token?grant_type=authorization_code&client_id=myclient&client_secret=mysecret&redirect_uri=https%3A%2F%2Fgraph.api.smartthings.com%2Foauth%2Fcallback&scope=app&code=XXXXX

Response:
200 OK
{
  "access_token": "43373fd2871641379ce8b35a9165e803",
  "expires_in": 1576799999,
  "token_type": "bearer"
}

Yeah, I was able to get the code correctly. I’m using the browser (chrome) to try to get the access token and I got the error I mentioned. So basically I’m using the url below by replacing the parameters (myclient, mysecret and code):

https://graph.api.smartthings.com/oauth/token?grant_type=authorization_code&client_id=myclient&client_secret=mysecret&redirect_uri=http://localhost&scope=app&code=XXXXX