Please note that this code is for demonstration purposes only and is not meant to be used in a production enviornment.

Copy/Paste at your own risk!

<?php
   /* getPartner(@param1, @param2)
    * 
    * Requests a Partner by creating a new cUrl instance and setting up the 
    * header for basic authentication using a valid Aegis Premier Technologies username and password.
    *
    * Example: $result = getPartner( "123456789", "id");
    *
    * @param1 The value to look up
    * @param2 The type of value to look up
    * 
    * @return The result as a string.
    */
    function getPartner($value, $type) 
    {
        $baseAddress = "https://uat-connect.aegispremier.com/api";
        $context = "Please contact Aegis Premier Technologies if you have not yet been assigned a Context variable.";
        $username = "AegisCRMUserName@example.com";
        $password = "AegisCRMPassword";

        $requestUri = $baseAddress . "/" . $context . "/";

        $cUrl = curl_init();

        // Set the data type to JSON and append the Aegis CRM login information to the Request header.			
        curl_setopt($cUrl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($cUrl, CURLOPT_HEADER, 1);
        curl_setopt($cUrl, CURLOPT_USERPWD, $username . ":" . $password);
        curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1);

        // Format the request
        curl_setopt($cUrl, CURLOPT_URL, $requestUri . "partner/" . $type . "/" . $value);

        // Send the request and retrieve the response.
        if( ! $result = curl_exec($cUrl)) 
        {
            trigger_error(curl_error($cUrl)); 
        }

        curl_close($cUrl);
                
        return $result;
    }
            
    echo getPartner("123456789", "id");
?>

<?php
    /* login($param1, $param2)
    * 
    * Requests a Partner by creating a new cUrl instance and setting up the 
    * header for basic authentication using a valid Aegis Premier Technologies username and password.
    *
    * It then creates a new JSON object representing a Log In form, and POSTs it to 
    * the API to retrieve the Partner object.
    * 
    * Example: $result = login("testUsrName", "testPassword");
    *
    * $param1 The partner's web user name
    * $param2 The partner's web password
    * 
    * @return The result as a string.
    */
    function login($partnerUserName, $partnerPassword) 
    {
        $baseAddress = "https://uat-connect.aegispremier.com/api";
        $context = "Please contact Aegis Premier Technologies if you have not yet been assigned a Context variable.";
        $username = "AegisCRMUserName@example.com";
        $password = "AegisCRMPassword";
        $requestUri = $baseAddress . "/" . $context . "/";

        $cUrl = curl_init();

        // Set the data type to JSON and append the Aegis CRM login information to the Request header.			
        curl_setopt($cUrl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($cUrl, CURLOPT_HEADER, 1);
        curl_setopt($cUrl, CURLOPT_USERPWD, $username . ":" . $password);
        curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1);

        // Create a new Log In object to pass the partner's credentials
        $data = array("Username" => $partnerUserName, "Password" => $partnerPassword);                                                                    
        $data_string = json_encode($data);  
                
        curl_setopt($cUrl, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
        curl_setopt($cUrl, CURLOPT_POSTFIELDS, $data_string);                                                                  

        // Format the request
        curl_setopt($cUrl, CURLOPT_URL, $requestUri . "partner/login");

        // Send the request and retrieve the response.
        if( ! $result = curl_exec($cUrl)) 
        {
            trigger_error(curl_error($cUrl)); 
        }

        curl_close($cUrl);
                
        return $result;
    }

    echo login("testUserName", "testPassword");
?>