Request is malformed trying to update a device using javascript

In testing out the Smartthings API I tried a very basic PUT command to update the label of a device:

let commands = [
label: “Test Phone”

var options = {
headers: {
Authorization: Bearer ${token}
method: ‘POST’,
body: commands,
json: true

returnValue.payload = request(options)
.then(function (parsedBody) {
.catch(function (err) {

But I get the following error: StatusCodeError: 405 - {“requestId”:“CE6C3EBD-8708-4A1F-B07C-AD9CA2FF00F4”,“error”:{“code”:“BadRequestError”,“target”:null,“message”:“The request is malformed.”,“details”:[]}}

Not sure why it’s taking my request is malformed? Looks like valid and very basic JSON just to update the label of a device?

Nevermind - I’m an idiot. I was using POST instead of PUT.

1 Like

To the best of my knowledge, there is no functional API to update Thing labels (or most other properties, other than Attributes, which must be updated using a web-services SmartApp in turn issuing a sendEvent()).

SmartTiles does not allow “configuration” by 3rd party applications…?

So it worked?

I thought the V1API was deprecated. Documentation?

They have an example right here where they update a device label:

1 Like

No - I haven’t gotten it to work yet. Hitting a different error now though so that’s progress I guess.

This is the error I’m getting now:
StatusCodeError: 500 - {“requestId”:“5D83E19C-1BA5-4EA5-B04D-962EF23039BC”,“error”:{“code”:“UnexpectedError”,“target”:null,“message”:“A non-recoverable error condition occurred.”,“details”:[]}}

Not many of us have experience with the new API yet (myself included, obviously). You may just be encountering temporary instability.

Tagging @jody.albritton ; (though Samsung may have a new developer forum too???).

Great. So I’m the guinea pig? :slight_smile:

1 Like

Malformed request. What kind of token are you using @richpowell

Full API Docs here

here is an example client in javascript

1 Like

Thanks - I seem to be making progress and have gotten quite a few parts of the API to work now.

The point of all this is that I’m writing a Node-RED script that will query my Unifi AP for a particular client (say, my cell phone) and then it will update a virtual presence sensor in SmartThings to be present if I’m at home and connected to the WiFi.

So the place where I’m blocked right now is that I’ve created a virtual presence device and I’m trying to send an event using the events API (I think this is how I’m supposed to do this?) Here’s my code:

var deviceEvents = { component: componentId, capability: 'presenceSensor', attribute: 'presence', value: 'present' };

var msg = {
‘method’: ‘POST’,
‘headers’ : {
‘Authorization’: Bearer ${token},
‘Content-Type’: ‘application/json’
‘url’: ${apiUrl}/devices/${deviceId}/events,
‘payload’: new Array(deviceEvents)

But I’m getting an “unauthorized” (403) error.

It is not permissible to be able to set events that change the presence of a presence sensor using this API?

are you using the oAuth and refresh token or the personal access token? The PAT will allow you basic access to the API but then you need to get an oAuth/refresh token for handling interactions with devices/apps

did you ever get this to work? i want to do the same thing now.

1 Like

I’m trying the the same and get 403

Can you tell me more about your specific scenario?