<?php 
require '../../curl/vendor/autoload.php';
    use Curl\Curl;

 $curl = new Curl();



$accessToken = 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjkzZjFkY2FjLTg5MjQtNDU3MS04ZWE5LWI3Mjc4MzY5Yzc5YiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjA2ODQxMzgzMTMsInN1YiI6IjU1ZmZkNTViNzMzMjJlNDQ3ZjVkMDgwMCIsImFsZyI6IlJTMjU2IiwiaXNzIjoia2luZ3NjaGF0IiwiYXVkIjpbImtpbmdzY2hhdCJdLCJhY2lkIjoiY29tLmtpbmdzY2hhdCIsImNpZCI6IjY2OGY4MDUwMDNlZGM0MzYyOWIxZGNhMSJ9.Gr2ZtMr93891UqzqfCPA3loUMCU90FwxMFzjuXIVna88MF9hOAJJJlQcjYQJzfTNQeq8w3VLT9tp73uGrQDq4qmL0QWlIW0VOswq4WZlyqOUNV6qiMcBAX7_ONoihzH-9jifzTqyZ1KF-i0Nd0jy5hlZCZYiNC42WtL4au017NRCtY8LYfUO6QWLHwApvTurKbg_U1ODb1YGhUYdhUSwRrwb8eqtno5NYAUgvV720-YmqAEo7bRO6khBa_uSGAuqU3h9veWeiaoJKFTwzGqU_5YlHJy26rI9_1TO9FBVy6r4XGkMqP-VFsvIEDl03i2XMAkiDzwu6_7Vdne1gc-i2g';

// Construct the API endpoint
$api_url = "https://connect.kingsch.at/api/users/550563a073312e129b9d0000/new_message/";

            $fullname = "Esteemed Pastor";
            $refcode = "REF";
            $zone = "Christ Embassy";
            $message = 
                "ZONAL MEETINGS WITH THE ESTEEMED DIRECTOR OF THE
 HEALING SCHOOL, ESTEEMED PASTOR DEOLA PHILLIPS
 
 *Highly Esteemed CEC Members Sirs,
 Esteemed Regional and Zonal Pastors,
 Esteemed Regional Secretaries*
 
 Warm greetings in the precious Name of our Lord, Jesus Christ.
 
 We are in top gear preparations for a world-shaking July Healing Streams Live Healing Services
 with our dear man of God, Pastor Chris. As announced during our Stakeholders Meeting on
 Friday, 28th June, I would like to have strategic zonal meetings with Group Pastors across the
 zones to crystallize our preparations and the celebration of our Triumphant Entry into Nations
 Through Healing Streams.
 
 As such, kindly take a minute to fill out the form attached to the link to pick the preferred date
 and time for this meeting to be held in your zone. Kindly click to fill out the form
 https://ethsch.org/2q9
 
 Thank you for your continual passionate commitment to the Healing School. I look forward to
 celebrating our exploits from this upcoming Healing Streams.
 
 God bless you
 
 Pastor Deola Phillips,
 Director, Healing School
";

$data = '{
    "message": {
        "body": {
            "text": {
              "body": "'.$message.'"
            }
          }
        }
      }';

// Initialize cURL session
$ch = curl_init();

// Set the URL to fetch
curl_setopt($ch, CURLOPT_URL, $api_url);

$headers = array(
   /* "Accept: application/application/json",*/
    "Content-Type:application/json",
    "Authorization: Bearer $accessToken",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// Return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Execute the cURL session and store the result in a variable
$response = curl_exec($ch);

// Check for cURL errors
if (curl_errno($ch)) {
    $users = null;
    $error = 'cURL error: ' . curl_error($ch);
    echo $error;
} else {
    var_dump($response);
}

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Close cURL session
curl_close($ch);

// Prepare JSON data for rendering

 if($httpcode != '200'){
    echo json_encode(array("statusCode"=>$httpcode, "responseData"=>$response)); 
 }else{
     echo json_encode(array("statusCode"=>201, "responseData"=>$response));
 }
 


?>

