Delete Record In CRM Module Using SDK PHP

Here we learn how to Delete records with ZOHP REST API using SDK in PHP.

To integrate ZOHO API Using SDK follow below step,

1) You need to create a ZOHO Application. If you have not created then please create by using the below link,

https://accounts.zoho.com/developerconsole

2) We need to include the vendor/autoload.php file. so first we need to install PHP SDK using composer.

  • Run the below command for install composer

    To install composer on mac/ Linux system use the below link:
    https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx

    To install composer on Windows system use the below link:

    https://getcomposer.org/doc/00-intro.md#installation-windows
  • Install PHP SDK
    1) Give the path of your client app(In which you want to add vendor folder).
    2) Run the command below:
    composer require zohocrm/php-sdk
  • The PHP SDK will be installed and a package named vendor would be created in the workspace of your client app.

3) To generate refresh code follow the step of the below URL,

https://www.thecodehubs.com/generate-access-code-using-postman-for-zoho

4) Create config.php file and add config file below code

return array (
  'userIdentifier'	   => 'testingtest@gmail.com',
  'client_id'		   => 'client_id',
  'client_secret'    	   => 'client_secreate key',
  'redirect_uri'	   => 'http://api.testing.com/sdk/function.php',
  'token_persistence_path' => 'zcrm_oauthtokens.txt',
  'scope'		   => 'ZohoCRM.modules.ALL',
  'refresh_code'	   => 'enter refresh code', // get refresh code using postman
);

Here,
client_id, client_secret, and redirect_uri that you get after registering your Zoho application.
token_persistence_path is a path for token storage;
Scope is Choose what data can be accessed by your application.
refresh code is code that is getting from the access token.

5) Create a delete-record.php file and add the below code in this file

class Delete_contacts{
    public function __construct()
    {
       global $client_id, $client_secret, $redirect_uri, $identifier, $token_persistence_path; 
        $configuration = array(
              "client_id"              => $client_id,
              "client_secret"          => $client_secret,
              "redirect_uri"           => $redirect_uri,
              "currentUserEmail"       => $identifier,
              "token_persistence_path" => $token_persistence_path
        );
        ZCRMRestClient::initialize($configuration);
    }
    
    public function delete_record() {
       $moduleDel = ZCRMRestClient::getInstance()->getModuleInstance("{Module_name}");
       $recordids = array(
            "410405000012345678",
            "410405000098765432"
        ); // record ids
       $responseDel = $moduleDel->deleteRecords($recordids); 
       foreach ( $responseDel->getEntityResponses() as $responsedel ) {
            echo "HTTP Status Code:" . $responseDel->getHttpStatusCode(); // To get http response code
            echo "Status:" . $responseDel->getStatus(); // To get response status
            echo "Message:" . $responseDel->getMessage(); // To get response message
            echo "Code:" . $responseDel->getCode(); // To get status code
            echo "Details:" . json_encode($responseDel->getDetails());
        }
    }
    public function delete_record_by_id() {
       $zcrmRecordDel = ZCRMRecord::getInstance( "{module_name}", record_id ); //record id
       $apiResponse = $zcrmRecordDel->delete(); 
       foreach ( $apiResponse->getEntityResponses() as $responsedel ) {
            echo "HTTP Status Code:" . $responseDel->getHttpStatusCode(); // To get http response code
            echo "Status:" . $responseDel->getStatus(); // To get response status
            echo "Message:" . $responseDel->getMessage(); // To get response message
            echo "Code:" . $responseDel->getCode(); // To get status code
            echo "Details:" . json_encode($responseDel->getDetails());
        }
    }
}

$obj = new Delete_contacts();
$obj->delete_record();
$obj->delete_record_by_id()

Where,
Module_name
: The API name of the module
record_id : Specific Record id which you want to update.
Possible_Module_name: leads, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, pricebooks, quotes, salesorders, purchaseorders, invoices, custom, and notes.

 

Submit a Comment

Your email address will not be published.

Subscribe

Select Categories