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
));