# HTTP request difficulties

**URL:** <https://community.gladysassistant.com/t/difficultes-requetes-http/7069>\
**Category:** Configuration\
**Created:** [March 15, 2022, 10:49pm UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069 "2022-03-15T22:49:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Checconio](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/checconio/32/19810_2.png) [@Checconio](https://community.gladysassistant.com/u/Checconio)\
**Post date:** [March 15, 2022, 10:49pm UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/1 "2022-03-15T22:49:48Z")

</div>

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:

```bash
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 😉 )

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

```bash
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.

 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/3/395fa1833461f00781d2e3ac184245d6233e479b.png)

Here is the response:

```bash
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 ‹&nbsp;X-Api-Key&nbsp;› 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 ‹&nbsp;-d&nbsp;› correspond to the Body part in Gladys, or is there no possibility to integrate data variables from Gladys?

Thanks

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [March 17, 2022, 6:11pm UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/2 "2022-03-17T18:11:02Z")

</div>

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! 🙂

> **[Build software better, together](https://github.com/GladysAssistant/Gladys/issues/new/choose)**
>
> GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.

---

<div class="post-metadata">

**Author:** ![Checconio](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/checconio/32/19810_2.png) [@Checconio](https://community.gladysassistant.com/u/Checconio)\
**Post date:** [March 17, 2022, 7:49pm UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/3 "2022-03-17T19:49:28Z")

</div>

A good bug report has been created [Button "try http request" in scene doesn't add headers properly · Issue #1473 · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/issues/1473) 😉

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

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![AlexTrovato](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/alextrovato/32/10705_2.png) [@AlexTrovato](https://community.gladysassistant.com/u/AlexTrovato)\
**Post date:** [March 17, 2022, 9:05pm UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/4 "2022-03-17T21:05:32Z")

</div>

The issue is that the «&nbsp;try&nbsp;» 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 «&nbsp;try&nbsp;» button, as we don’t have the «&nbsp;scope&nbsp;» that contains the variable values.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [March 18, 2022, 8:13am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/5 "2022-03-18T08:13:29Z")

</div>

> [@AlexTrovato](#):
>
> The problem is that the “try” button sends an array (array) but the backend method expects an object.

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

> [@AlexTrovato](#):
>
> But I think it will be complicated from the “try” button, because we don’t have the “scope”

Indeed, it’s another project! After that, we are not obliged to send the real values in a «&nbsp;try&nbsp;», 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 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [March 18, 2022, 8:28am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/6 "2022-03-18T08:28:35Z")

</div>

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

 ![Screenshot 2022-03-18 at 08.26.18](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/d/d9c28a96cefd218dcd61728063606ca8e0538dd6.jpeg)

 ![Screenshot 2022-03-18 at 08.27.07](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/d/d8c3b75b2bb13923bc4e52dd108c26cb476ddde7.png)

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [March 18, 2022, 8:33am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/7 "2022-03-18T08:33:37Z")

</div>

> [@Checconio](#):
>
> For my question at the end of the message, does a -d parameter in a curl correspond to the Body in Gladys?

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.

> [@Checconio](#):
>
> There is no possibility to integrate data variables from Gladys

What do you mean by «&nbsp;data variables&nbsp;»?

---

<div class="post-metadata">

**Author:** ![Checconio](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/checconio/32/19810_2.png) [@Checconio](https://community.gladysassistant.com/u/Checconio)\
**Post date:** [March 18, 2022, 9:40am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/8 "2022-03-18T09:40:07Z")

</div>

> [@pierre-gilles](#):
>
> What do you mean by «&nbsp;data variables&nbsp;»?

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

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

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

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [March 18, 2022, 9:51am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/9 "2022-03-18T09:51:48Z")

</div>

Top!

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

It’s in a PR here:

> <https://github.com/GladysAssistant/Gladys/pull/1475>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[\] If your changes affects code, did your write the tests?
> \- \[\] Are tests passing? (\`npm test\` on both front/server)
> \- \[\] Is the linter passing? (\`npm run eslint\` on both front/server)
> \- \[\] Did you run prettier? (\`npm run prettier\` on both front/server)
> \- \[\] If you are adding a new features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[\] Did you test this pull request in real life? With real devices? If this development is a big feature or a new service, we recommend that you provide a Docker image to \[the community\](https://community.gladysassistant.com/) for testing before merging.
> \- \[\] If your changes modify the API (REST or Node.js), did you modify the API documentation? (Documentation is based on comments in code)
> \- \[\] If you are adding a new features/services which needs explanation, did you modify the user documentation? See \[the GitHub repo\](https://github.com/GladysAssistant/v4-website) and the \[website\](https://gladysassistant.com).
> \- \[\] Did you add fake requests data for the demo mode (\`front/src/config/demo.js\`) so that the demo website is working without a backend? (if needed) See \[https://demo.gladysassistant.com\](https://demo.gladysassistant.com).
> 
> NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
> 
> \### Description of change
> 
> Please provide a description of the change here. It's always best with screenshots, so don't hesitate to add some!

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

---

<div class="post-metadata">

**Author:** ![Checconio](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/checconio/32/19810_2.png) [@Checconio](https://community.gladysassistant.com/u/Checconio)\
**Post date:** [March 18, 2022, 9:58am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/10 "2022-03-18T09:58:21Z")

</div>

No worries 😉  
And I confirm the correct functioning of my HTTP request after finding the right syntax 😃  
I will probably make a tutorial on sending SMS from Gladys 😛

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [March 18, 2022, 10:07am UTC](https://community.gladysassistant.com/t/difficultes-requetes-http/7069/11 "2022-03-18T10:07:56Z")

</div>

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