So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Link_Z
#76475 Hello everyone,

I'm trying to make my ESP8266 send a post to a specific endpoint of my API.
Now I'm getting a status "400" so I'd like to extract the property "error" of the json, but I don't know how to do so.

Here's what I have so far:

Code: Select all#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
 
void setup() {
 
  Serial.begin(115200);
  WiFi.begin("myssid", "mypass");
 
  while (WiFi.status() != WL_CONNECTED) { 
 
    delay(500);
    Serial.println("Waiting for connection");
 
  }
 
}

void loop()
{
  HTTPClient http;
   http.begin("http://192.168.1.44:5000/api/users/5b1e82fb8c620238a85646fc/arduinos/5b243dc666c18a2e10eb4097/data");
   http.addHeader("Content-Type", "application/json");
   http.addHeader("Authorization","Bearer mytoken");
   String payload = String("{'value' : 111111}");
   Serial.print("POST payload: "); Serial.println(payload);
   int httpCode = http.POST(payload);
   
   Serial.print("HTTP POST Response: "); Serial.println(httpCode);
   http.end();
 
   delay(10000);
}


Anyone could help me? I'm quite desperated after hours of trying to find the correct answer.

Thanks in advance.