API curl_error(): supplied resource is not a valid cURL handle resource

Hi,

I am trying to implement API and having issues. My PHP will send the request to an internal VM.

I encountered: curl_error(): supplied resource is not a valid cURL handle resource

Here is my script.

$apiUrl = ‘http://192.168.x.xx:82/api/resource/Lead’;
$apiKey = ‘key:secretkey’;

    // Prepare the data to create a new lead
    $leadData = array(
        'first_name' => $name,
        'email_id' => $email,
        'notes_html' => $message,
        'mobile_no' => $mobile,
        // Include other lead fields as necessary
    );


    // Make an HTTP POST request to create a new lead in ERPNext
    $ch = curl_init($apiUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($leadData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: token ' . $apiKey
    ));

Http Code 200
Notice : Undefined index: message in /home/erpnext_test.php on line 56
Failed to create lead.
Error:
Warning : curl_error(): supplied resource is not a valid cURL handle resource in /home/erpnext_test.php on line 57