HTTP request difficulties

Hello,

I’m having a small difficulty with HTTP POST requests.

Either it’s a bug, or I’m not using it correctly ^^

I have a working curl:

curl -X POST http://127.0.0.1:8080/raspisms/api/scheduled/ -H 'X-Api-Key: XXXXX' -d 'text=Mon%20SMS%20d%27exemple' -d 'numbers=%2B33000000000'

(Key and phone number intentionally masked :wink: )

I tried to pass it into Gladys’s HTTP request, and every time I got a response that the Api-Key was incorrect, even though it was the same as in the working curl.

Apache Log

127.0.1.1:80 127.0.0.1 - - [15/Mar/2022:23:20:29 +0100] "POST /raspisms/api/scheduled/ HTTP/1.1" 401 510 "-" "GladysAssistant/v4.8.0"

I wanted to know what Gladys was actually sending, so I created a test PHP page that displays the header content.

Here is the response:

Host: XXXXXXXX <br />
X-Real-IP: XX.XX.XXX.XXX <br />
X-Forwarded-Proto: https <br />
Connection: upgrade <br />
Content-Length: 0 <br />
0: [object Object] <br />
Accept: application/json, text/plain, */* <br />
Content-Type: application/x-www-form-urlencoded <br />
user-agent: GladysAssistant/v4.8.0 <br />
</body>
</html>

I don’t have the ‹ X-Api-Key › variable in the header that I passed.

Is this a bug or am I doing something incorrectly?

Another question in parallel, do my data parameters ‹ -d › correspond to the Body part in Gladys, or is there no possibility to integrate data variables from Gladys?

Thanks

I just ran a test, and I confirm there is a bug, it doesn’t work ^^

Can you create a GitHub issue with the same feedback? Thanks anyway for your feedback! :slight_smile:

A good bug report has been created Button "try http request" in scene doesn't add headers properly · Issue #1473 · GladysAssistant/Gladys · GitHub :wink:

Regarding my question at the end of the message, does a -d parameter in a curl correspond to the Body in Gladys?

Thanks :slight_smile:

The issue is that the « try » button sends an array, but the backend method expects an object.

@pierre-gilles I wanted to fix this issue, but I thought it would be interesting to also do the variable transformation with Handlebars. However, I think it will be complicated from the « try » button, as we don’t have the « scope » that contains the variable values.

Ah indeed! By the way, quick fix in the meantime, in my opinion @Checconio if you test your scene by « running » the scene instead of « trying » the HTTP block, it should work.

Indeed, it’s another project! After that, we are not obliged to send the real values in a « try », we can just send a placeholder for the variables. If we put a message to say that the variables will be replaced by test values, I think that can already be good :slight_smile:

I confirm the « hack » while waiting for the « try » bug to be fixed. If you test the scene via the « Start » button global to the scene, it works well:

Sorry, I missed this question, I had to do some research to find out.

I’m not a Curl expert, but I think so, basically the Gladys body corresponds to the body of an HTTP POST request.

What do you mean by « data variables »?

Data variables in curl are what actually make up the body.

So it’s the same thing between a curl and gladys after all :slight_smile:

I’m going to test my scene without using the try button, thanks :wink:

Top!

For information, I fixed the bug, it was very simple.

It’s in a PR here:

It will probably be included in the next release of Gladys. Thanks for your feedback :slight_smile:

No worries :wink:
And I confirm the correct functioning of my HTTP request after finding the right syntax :smiley:
I will probably make a tutorial on sending SMS from Gladys :stuck_out_tongue:

Awesome! Great idea for the tutorial, it will help a lot of people :slight_smile: