[Solved] Can you help me make a POST to Shelly using x-www-form-urlencoded calls?

I use web api for communication with device shelly

The get work fine

curl -X POST https://<server_uri>/device/status -d “id=<device_id>&auth_key=<auth_key>”

get

But the set Controlling device not work

curl -X POST https://<server_uri>/device/relay/control -d “channel=&turn=<on|off>&id=<device_id>&auth_key=<auth_key>”

The response is: {“isok”:false,“errors”:{“wrong_channel”:“Could not control this relay channel!”}}
error is: 400

post2

On this support

explains to make an https POST request and not GET , In the code I selected post but I can’t solve the problem

I have also tried sending the message as a body or as a header, but in all my tests the response is an invalid authorization!

The get worked after many trials and only worked using QueryParameters

Does that curl command work, for example in Terminal or Postman? If not, do you get the same error?

yes

according to the docs, I’d try something like this

Screen Shot 2022-05-23 at 10.15.26 AM

check out page 10 there.

You’ll need to set your Content-type header, and pass the data in as a string in the body of the POST

Thank you very much for your support!
I really tried them all, even with the get, if I don’t use “QueryParameters” it denies me permission.
here is the proof as you suggested and his response


risposta

can you give me a hint to see how thunkable web-api translates the code I wrote?
I would like to find a way to know if it really ships
curl -X POST https://<server_uri>/device/relay/control -d “channel=&turn=<on|off>&id=<device_id>&auth_key=<auth_key>”
as I asked it to do

header
If I use header instead this happens

I also found a post where it said to do this but commqua it doesn’t work and gives the same message as above

Without this call my app is meaningless!
If anyone can help me I would be very grateful.
To try it would just need to install his shelly cloud app, that way you can have your “auth_key” then I share a device with you just by stating your email with which you registered in the app and so you also have in id device to try it.
Would anybody do that?

1 Like

You are not putting commands in the correct order, this is why you are not getting results.

You need to set it this way:

Replace server_uri, device_id, auth_key with the relevant values.

1 Like

:arrow_up: :arrow_up: :arrow_up:

Looks spot on! Please try out @muneer’s advice @ferrarofcfei and let us know how you get along! :slight_smile:

1 Like

Thank you, I did several tests following your advice, but I’ll tell you what I found out.

  1. the get with /device/status was already working for me using the queryParameter, in this case I need a set using a POST and thus doing a /device/relay/control
  2. I tried from promt and the curl command and even mixing the parameters the device always responds, so it seems that the order is not important
  3. I still tried your sequence (and mine which i put the picture below) and it doesn’t work because it gives the error “header property …”
    4 I tried removing the body altogether and it gives the same error “header property…” so time there is a problem in the headers


1 Like

Try removing this block
image

And just use the rest of the blocks.
image

This is extracted from this
image

1 Like

nothing


@muneer if you install the shelly cloud app, that way you can have your “auth_key” after I share a device with you and you have an id device to try it.
would you do me this favor.

1 Like

Sure.
I’ll do that tomorrow. It’s about 1am in the morning my time.

1 Like

@muneer thank you very much, please allow me to unblock the app that stops on this issue. When you install the “Shelly Cloud” app please send me your email to share my device with you.

1 Like

hey guys i just can’t find the solution :frowning:

1 Like

I registered in the cloud. Please send me your device ID in a PM.

1 Like

send me your email in PM to share my device and have the ability to manage it

is there any way to know how to format the web-api command i wrote?

1 Like