Automation Smartapp permission problem

Hi.

I want to make a virtual device on automation smartapp.
I made a deviceprofile on smartthings cli.

When I don’t set a permissions in code and request a make a device, I got a 403 code.

When I set a permissions in code, that’s not working (I can’t enter the smartapp)

This is my test code

var smartApp = new SmartApp({})
smartApp.enableEventLogging(2)
.configureI18n() // Language file in ./locales folder
.appId(appId)
.disableCustomDisplayName(true)
.permissions([
“r:locations:*”
])
.page(“mainPage”, (context, page, configData) => {
page.section(“test”, section => {
section.textSetting(“testip”)
.description(“IP address of device”)
.defaultValue("")
.required(true)
})
})
.updated(async (context, updateData) => {
await context.api.subscriptions.unsubscribeAll();
})

server debug
2021-02-04T09:51:11.554Z debug: CONFIGURATION/INITIALIZE REQUEST: {
“lifecycle”: “CONFIGURATION”,
“executionId”: “51f4d95b-1259-f3f4-7386-1403b3078803”,
“appId”: “de7eab80-ebe2-413b-b1f1-3b37f2e38cbf”,
“locale”: “ko”,
“version”: “0.1.0”,
“client”: {
“os”: “android”,
“version”: “1.7.59.23”,
“language”: “ko-KR”,
“displayMode”: “LIGHT”,
“timeZoneOffset”: “”,
“supportedTemplates”: ,
“samsungAccountId”: “”
},
“configurationData”: {
“installedAppId”: “a2e2b3c9-6b44-4624-9367-5dac3ddf4268”,
“phase”: “INITIALIZE”,
“pageId”: “”,
“previousPageId”: “”,
“config”: {},
“isResubmit”: true
},
“settings”: {}
}
2021-02-04T09:51:11.554Z debug: RESPONSE: {
“statusCode”: 200,
“configurationData”: {
“initialize”: {
“firstPageId”: “mainPage”,
“permissions”: [
“r:locations:*”
],
“disableCustomDisplayName”: true,
“disableRemoveApp”: false
}
}
}

Hey @fison67

You may need to remove the .configurei18n() line to access the SmartApp page. I always remove it to avoid conflicts while deploying SmartApps.

Also, to create the device, there are a few scopes that you need to include at your SmartApp Instance:

  • w:devices:* to be able to create the virtual device.
  • i:deviceprofiles:* to be able to use your device profiles from the SmartApp context.

For reference, you can check this basic implementation that I wrote to test this out.

@erickv Thanks!
I success to create the virtual device.

And I want to notify message to st app, I tried it but got a 401 error.
What do I need a scope?

This is my code.
ctx.api.notifications.create({
locationId: ctx.api.config.locationId,
type: ‘ALERT’,
messages: [{‘ko-KR’:{title: “title”, body:“content”}}],
deepLink: {type: ‘installedApp’, id:“test”},
imageUrl: “https://t1.kakaocdn.net/kakaocorp/corp_thumbnail/Kakao.png
})

RESPONSE: {
“statusCode”: 500,
“message”: “Server error: ‘Error: Request failed with status code 401: {“requestId”:“AF4C68C8-C5B1-43F7-8EED-7FEC0B38E663”,“error”:{“code”:“UnauthorizedError”,“target”:null,“message”:“Invalid scope”,“details”:}}’”

And one more question.
I have a two location in st ide.
Whenever I install a automation smartapp, always one location is selected.
It’s a first location.

Is it possible to select a location before installed a app?

Thanks for your help.

Nice! I’m glad that it worked.

Now, about your last questions:

The Notifications API is not public yet, but let me double-check it.


As for your last question, you cannot change the location on the fly, but installing the SmartApp at the desired location will generate a new location context for your SmartApp Instance.

1 Like

Good news @fison67!

As there’s no official documentation about the Notifications API, you can base your configuration on the notification.ts module from the SmartThings Core SDK.

Actually, it is very simple, check this “hello world” example to have a basic reference on how to implement it.

Note: Specifying posts as Solutions will help other to fast track them if they need.

1 Like

@erickv Thank you so much!

It’s working!!!

I’m sorry I keep asking
I hope this is a last question.

On smartapp list, it’s showing only title without description.
And I have no idea how to set an icon.

Great! it’s good to know that it’s working on your side as well.


You mean the icon from the Installed SmartApps section, right? If so, this feature is only available for published/certified SmartApps (this applies for the SmartApp Catalog as well).

How does deepLink work for type: installedApp? When using the app’s ID it produces “Unable to view details” on the SmartThings app. I’d expect it to open the installed app?

{
  "type": "AUTOMATION_INFO",
  "message": "This is a handy message",
  "title": "Look at me!",
  "locationId": "*my-location-id*",
  "imageUrl": "---",
  "deepLink": {
    "type": "installedApp",
    "id": "*my-app-id*"
  }
}

I couldn’t replicate the issue you mention. You’re not using the SDK (SmartApp or Core), right?
This feature is still under our engineering team review. Currently, no matter which deepLink type you use, the push notification is the same.

If I do a location deepLink instead of a ‘installedApp’ deepLink, the action of clicking the notification takes you to the location.

...
  "deepLink": {
    "type": "location",
    "id": "*my-location-id*"
  }
...

The above works to take you to the location of the location ID in the SmartThings app.

...
  "deepLink": {
    "type": "installedApp",
    "id": "*my-app-id*"
  }
...

This, I would expect to take you to the app config page. But isn’t working. I was just wondering if I was providing the wrong thing for “id” and providing something else would work.

It makes sense this doesn’t work if it’s still in dev. Thank you.