Do SmartThings Schema Interaction Types have updating and deleting device function?

Based on the SmartThings Schema Interaction Types, may I ask if there is any method to implement deleting device and updating device(friendlyName) through SmartThings Schema Interaction Types?

For example, if I change the name of my device, the device name can also be changes in SmartThings APP. If I delete a device in my APP, the device can also be deleted in SmartThings APP.

I tried to do send the new familyName in discoveryCallback while changing the device name, but It seems not the way I thought to change the device name.

If not, is there any other way?

I tried API(API | SmartThings Developers) and Personal Access Tokens to retrieve deviceID so that I can update certain device label or delete device, but it seems not workable. Because each Personal Access Tokens is corresponding to the user’s Samsung Account. Once the project is published, Other users will have their own accounts. Using API and Personal Access Tokens which is generated from my account cannot find others’ devices.

Thanks,

Hi!

To delete the device, you need to send the corresponding global error in a stateCallback. Here’s a post where I shared more information about the deletion process:

This cannot be done, the friendlyName parameter is only considered when the device is discovered for the first time. Please, take a look at this post:

That discussion seems to unlink the account or integration instead of deleting a device. What I asked is to initiate deleting a certain device from my side. If that is doable, the callback payload should have externalDeviceId to delete a certain device.

Or like this? Which is modified from device error example here.

{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "stateCallback",
        "requestId": "abc-123-456"
    },
    "authentication": {
        "tokenType": "Bearer",
        "token": "token-received from SmartThings for callbacks"
    },
    "deviceState": [
        {
            "externalDeviceId": "partner-device-id-1",
            "deviceError": [
              {
                "errorEnum": "DEVICE-DELETED",
                "detail": "more detail from the partner"
              }
            ]
        }
    ]
}

How about the API and Personal Access Tokens method I mentioned? Is my understanding right?

Oh, sorry about that.

Let me make some tests and I’ll get back to you.

Update:
@exosite, the team confirmed you can use that error to delete the device from a stateCallback, just remember that, if you send the device again in a discoveryResponse, it will be created:

"deviceState": [
    {
        "externalDeviceId": "pdevice-1",
        "deviceError": [
            {
                "errorEnum": "DEVICE-DELETED",
                "detail": "messageDetail"
            }
        ]
    }
]

Yes, that can be done through the API but only by the owner, external PATs like yours cannot interact with the Connector’s users’ devices.

Also, here’s an example using the ST Schema NodeJS SDK:

let deviceState = [
    {
     externalDeviceId:"device-id",
     deviceError:[
       {
         errorEnum: "DEVICE-DELETED",
         detail: "Device deleted by third"
       }
     ]
   }
 ]
const updateRequest = new StateUpdateRequest(process.env.ST_CLIENT_ID, process.env.ST_CLIENT_SECRET);

updateRequest.updateState(accessTokens.callbackUrls, accessTokens.callbackAuthentication, deviceState)
.catch((error)=>{// the request shouldn't be successful as the error causes an exception that will delete the device
    console.log("delete success ", error)
})

Yeah, it works. Thanks for help!

1 Like

The updateState function requires a callbackAuth object with an accessToken.

Can you give us an example of how to get the accessToken and refreshToken from this URL?
https://c2c-us.smartthings.com/oauth/token

I have this information from the grantCallbackAccess request from ST, but I don’t know how to format the request to that /oauth/token ST endpoint.

    "callbackAuthentication": {
        "grantType": "authorization_code",
        "scope": "callback-access",
        "code": "my_code",
        "clientId": "my_client_id"
    },
    "callbackUrls": {
        "oauthToken": "https://c2c-us.smartthings.com/oauth/token",
        "stateCallback": "https://c2c-us.smartthings.com/device/events"
    }

EDIT:
Nevermind. I figured it out. This request worked:

{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "accessTokenRequest",
        "requestId": "ca142225-2375-49bd-8a09-9bc6cbf2e123"
    },
    "callbackAuthentication": {
        "grantType": "authorization_code",
        "scope": "callback-access",
        "code": "my_code",
        "clientId": "my_client_id",
        "clientSecret": "my_client_secret"
    }
}
1 Like

@nayelyz
Is there any way to handle a single device deletion from SmartThings? How will my connector know that a device has been deleted?

Hi, @Surabhi_S!
Do you mean when a user deletes the device from the third-party cloud and you need to delete it from the SmartThings side?
If so, you can send from your cloud a device global error called “DEVICE-DELETED” in a State callback. For example:

const deviceState = [
   {
    externalDeviceId:"external-dev-id",
    deviceError:[
      {
        errorEnum: "DEVICE-DELETED",
        detail: "Device deleted by third"
      }
    ]
  }
]
const updateRequest = new StateUpdateRequest(ST_CLIENT_ID, ST_CLIENT_SECRET);

updateRequest.updateState(accessTokens.callbackUrls, accessTokens.callbackAuthentication, deviceState)
.catch((error)=>{
console.log("delete success ", error)
})