Skip to main content

PHP SDK Samples - Profile Operations

Get All Profiles
              
              
<?php
namespace com\zoho\crm\sample\profile;
use com\zoho\crm\api\profiles\APIException;
use com\zoho\crm\api\profiles\ProfilesOperations;
use com\zoho\crm\api\profiles\ResponseWrapper;
class Profile
{
    /**
     * Get Profiles
     * This method is used to retrieve the data of profiles through an API request and print the response.
     * @throws Exception
     */
    public static function getProfiles()
    {
        //example
        //moduleAPIName = "Leads";
        
        //Get instance of ProfilesOperations Class
        $profilesOperations = new ProfilesOperations();
        
        //Call getProfiles method
        $response = $profilesOperations->getProfiles();
        
        if($response != null)
        {
            //Get the status code from response
            echo("Status code " . $response->getStatusCode() . "\n");

            if(in_array($response->getStatusCode(), array(204, 304)))
            {
                echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");

                return;
            }
            
            //Get object from response
            $responseHandler = $response->getObject();
                
            if($responseHandler instanceof ResponseWrapper)
            {
                //Get the received ResponseWrapper instance
                $responseWrapper = $responseHandler;
                
                //Get the list of obtained Profile instances
                $profiles = $responseWrapper->getProfiles();
            
                foreach($profiles as $profile)
                {
                    //Get the DisplayLabel of the each Profile
                    echo("Profile DisplayLabel: " . $profile->getDisplayLabel() . "\n");
                    
                    if($profile->getCreatedTime() != null)
                    {
                        //Get the CreatedTime of each Profile
                        echo("Profile CreatedTime: ");
                        print_r($profile->getCreatedTime());
                        echo("\n");
                    }
                    
                    if($profile->getModifiedTime() != null)
                    {
                        //Get the ModifiedTime of each Profile
                        echo("Profile ModifiedTime: ");
                        print_r($profile->getModifiedTime());
                        echo("\n");
                    }
                    
                    //Get the Name of the each Profile
                    echo("Profile Name: " . $profile->getName() . "\n");
                    
                    //Get the modifiedBy User instance of each Profile
                    $modifiedBy = $profile->getModifiedBy();
                    
                    //Check if modifiedBy is not null
                    if($modifiedBy != null)
                    {
                        //Get the ID of the modifiedBy User
                        echo("Profile Modified By User-ID: " . $modifiedBy->getId() . "\n");
                        
                        //Get the name of the modifiedBy User
                        echo("Profile Modified By User-Name: " . $modifiedBy->getName() . "\n");
                        
                        //Get the Email of the modifiedBy User
                        echo("Profile Modified By User-Email: " . $modifiedBy->getEmail() . "\n");
                    }
                    
                    //Get the Description of the each Profile
                    echo("Profile Description: " . $profile->getDescription() . "\n");
                    
                    //Get the ID of the each Profile
                    echo("Profile ID: " . $profile->getId() . "\n");
                    
                    //Get the Category of the each Profile
                    echo("Profile Category: " . $profile->getCategory() . "\n");
                    
                    //Get the createdBy User instance of each Profile
                    $createdBy = $profile->getCreatedBy();
                    
                    //Check if createdBy is not null
                    if($createdBy != null)
                    {
                        //Get the ID of the createdBy User
                        echo("Profile Created By User-ID: " . $createdBy->getId() . "\n");
                        
                        //Get the name of the createdBy User
                        echo("Profile Created By User-Name: " . $createdBy->getName() . "\n");
                        
                        //Get the Email of the createdBy User
                        echo("Profile Created By User-Email: " . $createdBy->getEmail() . "\n");
                    }
                }
            }
            //Check if the request returned an exception
            else if($responseHandler instanceof APIException)
            {
                //Get the received APIException instance
                $exception = $responseHandler;
            
                //Get the Status
                echo("Status: " . $exception->getStatus()->getValue() . "\n");
                
                //Get the Code
                echo("Code: " . $exception->getCode()->getValue() . "\n");
                
                echo("Details: " );
                
                //Get the details map4
                foreach($exception->getDetails() as $key => $value)
                {
                    //Get each value in the map
                    echo($key . ": " .$value . "\n");
                }
                
                //Get the Message
                echo("Message: " . $exception->getMessage()->getValue() . "\n");
            }
        }
    }
}
Get Specific Profile