I tested your code and found an error on your prepared POST data. The library http.client isn't necessary and the data must be encoded in json format. I add the json library and encode the data properly. I leave you the reviewed code.