Psyduck - 可達鴨 之 鴨力山大 v0.1

Current Path : home/irplbiz/www/demo_dev/demo_crm/
Upload File :
Current File : /home/irplbiz/www/demo_dev/demo_crm/submit_form_bkphp

<?php

// SuiteCRM API credentials and URL
$crm_url = "https://orionedutech.co.in/suite/service/v4_1/rest.php";
$crm_username = "manjari";
$crm_password = "manjari";

// Form data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

// Step 1: Get an API token
$token_url = $crm_url . "/oauth2/token";
$token_payload = json_encode([
    'grant_type' => 'password',
    'client_id' => 'rest',
    'client_secret' => 'rest',
    'username' => $crm_username,
    'password' => $crm_password
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $token_payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$response = curl_exec($ch);
curl_close($ch);

$response_data = json_decode($response, true);
$access_token = $response_data['access_token'];

// Step 2: Create a new lead in SuiteCRM
$lead_url = $crm_url . "/Leads";
$lead_payload = json_encode([
    'first_name' => $first_name,
    'last_name' => $last_name,
    'email1' => $email,
    'phone_work' => $phone
]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $lead_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $lead_payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $access_token,
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
curl_close($ch);

// Handle the response
if ($response) {
    echo "Lead created successfully in SuiteCRM!";
} else {
    echo "There was an error creating the lead in SuiteCRM.";
}
?>