401 Error with smartthings api

Hi, I'm trying to access the smartthings API, and I can't get past the part with the authentication key/bearer token. This is what I have been trying, and it shows a 401, which is authorization required.

A quick look at the api documentation indicates that they use Basic Authentication.

This means you may need to pass the Authorization token in a different way in the url.

See here for how @Taifun did it:

https://puravidaapps.com/filedownload.php#restricted

1 Like

Thanks, That worked. I now have a slightly more complicated question. I'm trying to turn my lights off from MIT app inventor as an experiment, and using "postman" I was able to do it successfully. I just need help translating this into app inventor. The picture on the bottom does not work.


Try the PostText block, you are not posting a file.

If that doesn't work try building a dictionary instead of a list

If that doesn't work try adding the json to your Web1.Url

It slightly fixed it, but im getting a 422, which is a constraint violation error. this is probably how I formatted the big chunk of lists. Sorry for the complications, I'm fairly new and just want to experiment some things outside of my csp class

I tried what I was doing before, but it still give a 422 error. I also tried using a dictionary (never used it before, attached screenshot), but it still does not work. I have observed that in the postman part, that the API is really picky at formatting, and only wants it the way in the picture above this comment, particularly the "argument" section. I think it might be something wrong with my entire chunk formating, or just the "argument." Do you think you can help me out? Thanks
Ty for all ur help so far

Use the PostText method and put together your JSON manually exactly as you are using it in Postman using text blocks without list blocks and post a screenshot of your updated blocks

Taifun

I'm not too sure what you mean by pasting my JSON, do you think you could provide an example? Also I forgot to attach a screenshot above, here is my attempt with a dictionary.

Oh, I figured out how to paste the JSON into a textbox and it now works. I still want to learn conceptually how to make a list or dictionary to represent the same thing. Do you think you could guide me through it, maybe draw a picture or something? Tysm

text block...
What about posting an updated screenshot?
Taifun

Try this

and try a create empty list block instead of the empty text block

Taifun


I just directly pasted whatever was in postman and it seems to work
I will now attempt what you put below


Is this what you meant? It returns the 422 malformed request error code. I have tried both putting the list in there with a 0 and removing the text box.

Try to add another make a list block here


and use a create empty list block there

http://ai2.appinventor.mit.edu/reference/blocks/lists.html#emptylist

Taifun


I'm not too sure if this is what you were indicating, but this (screenshot attached) still gives the same error., 422 constraint violation error, body malformed

Yes, for me this looks correct...
Sorry, I do not have another idea...
Sometimes it is easier to continue using the solution you already have

Taifun

okay, thanks for ur help though!