Problem sending data in json format using at+httpclient in put

MVillars
Posts: 1
Joined: Thu Sep 15, 2022 7:56 am

Problem sending data in json format using at+httpclient in put

Postby MVillars » Thu Sep 15, 2022 8:33 am

Hello,

I am using an esp32-C3-mini-1.
I would like to send a PUT command using AT+ HTTPCLIENT with data in json format.

Example of a functional cURL command (tested on my LINUX terminal) that I want to send as an AT command:

curl -v -X PUT -H "Content-Type: application/json" -d '{"data":{"credentials": "80851851709e01bc9453cced585a7bca", "account_name": "name", "method": "md5"}}' https:/************/v2/user_auth

Note: for privacy reasons, the server URL is replaced by ********

I tried different ways to write the command in AT+HTTPCLIENT, here are the two examples below with the errors returned by the server:

1/Command sent
AT+HTTPCLIENT=4,1,"https://************//v2/user_auth",,,2,"{\"data\":{\"credentials\":\"80851851709e01bc9453cced585a7bca\"\,\"account_name\":\"name"\,\"method\":\"md5\"}}"

Response returned
+HTTPCLIENT:323,{"data":{"credentials":{"required":{"message":"Field is required but missing","value":"credentials"}}},"error":"400","message":"validation error","status":"error","timestamp":"2022-09-09T10:28:38Z","version":"4. 3.137","node":"2F3uVbINGAQENHWG6esPUQ","request_id":"8813e33e705c4a1afb9752992fe068da","auth_token":"undefined"}

I tried another way based on the examples provided by the doc (https://docs.espressif.com/projects/esp ... mples.html) but the problem is a body we want to send and not parameters.

2/Command sent
AT+HTTPCLIENT=4,1,"https://************v2/user_auth?credentials=80851851709e01bc9453cced585a7bca&account_name=name&method=md5",,,2

Returned answer
+HTTPCLIENT:323,{"data":{"credentials":{"required":{"message":"Field is required but missing","value":"credentials"}}},"error":"400","message":"validation error","status":"error","timestamp":"2022-09-09T11:40:58Z","version":"4. 3.137","node":"2F3uVbINGAQENHWG6esPUQ","request_id":"6cece3d9c7280ddbfb2bb1f4c287c3cf","auth_token":"undefined"}

How can we write the command to make it work?

Thanking you in advance for your valuable help.

boarchuz
Posts: 598
Joined: Tue Aug 21, 2018 5:28 am

Re: Problem sending data in json format using at+httpclient in put

Postby boarchuz » Thu Sep 15, 2022 9:34 am

MVillars wrote:
Thu Sep 15, 2022 8:33 am
... bca\"\,\"account_name\":\"name"\,\"met ...
Some of these escape sequences don't look right. Double check the quoted part above.

Use something like https://webhook.site to check that the server is receiving what you expect.

ESP_Sun
Posts: 320
Joined: Thu Dec 30, 2021 9:52 am

Re: Problem sending data in json format using at+httpclient in put

Postby ESP_Sun » Mon Sep 19, 2022 11:46 am

MVillars wrote:
Thu Sep 15, 2022 8:33 am
Hello,

I am using an esp32-C3-mini-1.
I would like to send a PUT command using AT+ HTTPCLIENT with data in json format.

Example of a functional cURL command (tested on my LINUX terminal) that I want to send as an AT command:

curl -v -X PUT -H "Content-Type: application/json" -d '{"data":{"credentials": "80851851709e01bc9453cced585a7bca", "account_name": "name", "method": "md5"}}' https:/************/v2/user_auth

Note: for privacy reasons, the server URL is replaced by ********

I tried different ways to write the command in AT+HTTPCLIENT, here are the two examples below with the errors returned by the server:

1/Command sent
AT+HTTPCLIENT=4,1,"https://************//v2/user_auth",,,2,"{\"data\":{\"credentials\":\"80851851709e01bc9453cced585a7bca\"\,\"account_name\":\"name"\,\"method\":\"md5\"}}"

Response returned
+HTTPCLIENT:323,{"data":{"credentials":{"required":{"message":"Field is required but missing","value":"credentials"}}},"error":"400","message":"validation error","status":"error","timestamp":"2022-09-09T10:28:38Z","version":"4. 3.137","node":"2F3uVbINGAQENHWG6esPUQ","request_id":"8813e33e705c4a1afb9752992fe068da","auth_token":"undefined"}

I tried another way based on the examples provided by the doc (https://docs.espressif.com/projects/esp ... mples.html) but the problem is a body we want to send and not parameters.

2/Command sent
AT+HTTPCLIENT=4,1,"https://************v2/user_auth?credentials=80851851709e01bc9453cced585a7bca&account_name=name&method=md5",,,2

Returned answer
+HTTPCLIENT:323,{"data":{"credentials":{"required":{"message":"Field is required but missing","value":"credentials"}}},"error":"400","message":"validation error","status":"error","timestamp":"2022-09-09T11:40:58Z","version":"4. 3.137","node":"2F3uVbINGAQENHWG6esPUQ","request_id":"6cece3d9c7280ddbfb2bb1f4c287c3cf","auth_token":"undefined"}

How can we write the command to make it work?

Thanking you in advance for your valuable help.
Hi,

It looks like the " and \ are not escaped in your command.
企业微信截图_16635877489586.png
企业微信截图_16635877489586.png (16.72 KiB) Viewed 2868 times

Who is online

Users browsing this forum: No registered users and 46 guests