I found some examples about post and get methods using curl, but I am not able to deal with the server internal error 500. The google console reports error 500 of fetch type. I checked my php configuration and seems to be ok. Context: function in functions.php of a wordpress installation based on elementor template. Ionos hosting. How can I debug this issue?
      $url = 'https://myurl.com/';
    
      $fields = array('var1' => 'value1', 'var2' => 'value2');
      $headers = array('X-MY-TOKEN: tokenValue', 'Content-Type: application/json');
    
      $fields_json = json.encode($fields);
      
      //open connection
      $ch = curl_init();
    
      //setup
      curl_setopt($ch,CURLOPT_URL, $url);
      curl_setopt($ch,CURLOPT_POST, 1);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_json);
      curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
    
      //execute post
      $response = curl_exec($ch);
Update:the php log error shows: PHP Fatal error:  Uncaught Error: Call to undefined function encode()
How to send then a POST with application/json content-type?

 
    