Help with API

I’m looking for a bit of help getting the client ID via a CURL command, basically finding the ID by email address so I can do a quick if they exist update, if not create command.

This is what I have so far, but I can’t find a way to grab the ID from the array

I’m using self-hosted


<?php

    function cURLclients($url) {

        // Create a new cURL resource
        $curl = curl_init(); 

        if (!$curl) {
            die("Couldn't initialize a cURL handle"); 
        }

        // Set the file URL to fetch through cURL
        curl_setopt($curl, CURLOPT_URL, "https://MYURLapi/v1/clients?email=" . $url);

        // Follow redirects, if any
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 

        // Fail the cURL request if response code = 400 (like 404 errors) 
        curl_setopt($curl, CURLOPT_FAILONERROR, true); 

        // Return the actual result of the curl result instead of success code
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        // Wait for 10 seconds to connect, set 0 to wait indefinitely
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);

        // Execute the cURL request for a maximum of 50 seconds
        curl_setopt($curl, CURLOPT_TIMEOUT, 50);
		
		        // Execute the cURL request for a maximum of 50 seconds
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
		
				        // Execute the cURL request for a maximum of 50 seconds
        curl_setopt($curl, CURLOPT_POST, "GET === 'POST' ? 1 : 0");
		$token = 'MYTokEN';
		curl_setopt($curl, CURLOPT_HTTPHEADER, [
	            'Content-Type: application/json',
	            'X-Ninja-Token: '. $token,
	        ]);

        // Do not check the SSL certificates
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 

        // Fetch the URL and save the content in $html variable
        $html = curl_exec($curl); 

        // Check if any error has occurred 
        if (curl_errno($curl)) 
        {
            echo 'cURL error: ' . curl_error($curl); 
        } 
        else 
        { 
            // cURL executed successfully
            
			return $html;
        }

        // close cURL resource to free up system resources
        curl_close($curl);
    }
	
	$clients = cURLclients('email@tofind.com');
	$clients = str_replace('"', "", $clients);

	$convert_to_array = explode(',', $clients);

for($i=0; $i < count($convert_to_array ); $i++){
    $key_value = explode(':', $convert_to_array [$i]);
    $end_array[$key_value [0]] = $key_value [1];
}
print_r($end_array);
$reversed = array_flip($end_array);
echo "<br><Br><br>";
print_r($reversed);
echo "<br><Br><br>::";

$count = (count($end_array));
if ($count <10) {
//CREATE NEW RECORD	
	
echo "nothing";
}
else {
echo "found it";
//UPDATE RECORD

}

?>