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.
Problem sending data in json format using at+httpclient in put
Re: Problem sending data in json format using at+httpclient in put
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.
Re: Problem sending data in json format using at+httpclient in put
Hi,MVillars wrote: ↑Thu Sep 15, 2022 8:33 amHello,
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.
It looks like the " and \ are not escaped in your command.
Who is online
Users browsing this forum: No registered users and 14 guests