PHP SDK Samples - Note Operations

Get Attachments of a Note
              
              
<?php
    use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
    require 'vendor/autoload.php';
    class Note{
        public function __construct()
        {
            $configuration = array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
            ZCRMRestClient::initialize($configuration);
        }
        
public function getAttachmentsOfNote(){
        $noteIns = ZCRMNote::getInstance(null, "3524033000003358002"); // to get the note instance
        $responseIns = $noteIns->getAttachmentsOfNote(1, 50); // to get the attachments
        $attachments = $responseIns->getData(); // to get the attachments in form of ZCRMAttachment instance array
        foreach ($attachments as $attchmentIns) {
            echo $attchmentIns->getId(); // To get the note's attachment id
            echo $attchmentIns->getFileName(); // To get the note's attachment file name
            echo $attchmentIns->getFileType(); // To get the note's attachment file type
            echo $attchmentIns->getSize(); // To get the note's attachment file size
            echo $attchmentIns->getParentModule(); // To get the note's attachment parent module name
            $parentRecord = $attchmentIns->getParentRecord();
            echo $parentRecord->getEntityId(); // To get the note's parent record id
            echo $attchmentIns->getParentName(); // To get the note name
            $createdBy = $attchmentIns->getCreatedBy();
            echo $createdBy->getId(); // To get user_id who created the note's attachment
            echo $createdBy->getName(); // To get user name who created the note's attachment
            $modifiedBy = $attchmentIns->getModifiedBy();
            echo $modifiedBy->getId(); // To get user_id who modified the note's attachment
            echo $modifiedBy->getName(); // To get user name who modified the note's attachment
            $owner = $attchmentIns->getOwner();
echo $owner->getId(); // To get the note's attachment owner id
            echo $attchmentIns->getCreatedTime(); // To get attachment created time
            echo $attchmentIns->getModifiedTime(); // To get attachment modified time
        }
    }
    }
$obj =new Note();
$obj->getAttachmentsOfNote();

 
Upload Attachment to a Note
              
              
<?php
    use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
    require 'vendor/autoload.php';
    class Note{
        public function __construct()
        {
            $configuration = array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
            ZCRMRestClient::initialize($configuration);
        }
         public function uploadAttachmentToNote(){
        $filepath = '/Users/index.jpg';
        $noteIns = ZCRMNote::getInstance(null, "3524033000003358002"); // to get the note instance
        $response = $noteIns->uploadAttachment($filepath);
        echo "HTTP Status Code:" . $response->getResponseJSON(); // To get http response code
        echo "Status:" . $response->getStatus(); // To get response status
        echo "Message:" . $response->getMessage(); // To get response message
        echo "Code:" . $response->getCode(); // To get status code
        echo "Details:" . $response->getDetails()['id'];
    }
    }
$obj =new Note();
$obj->uploadAttachmentToNote();
 
Download Attachment from a Note
              
              
<?php
    use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
    require 'vendor/autoload.php';
    class Note{
        public function __construct()
        {
            $configuration = array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
            ZCRMRestClient::initialize($configuration);
        }
        
 public function downloadAttachmentFromNote(){
        $noteIns = ZCRMNote::getInstance(null, "3524033000003358002"); // to get the note instance
        $fileResponseIns = $noteIns->downloadAttachment("3524033000003393001");
        $filePath = "/Users/";
        $fp = fopen($filePath.$fileResponseIns->getFileName(), "w"); // $filePath - absolute path where downloaded file has to be stored.
        echo "HTTP Status Code:" . $fileResponseIns->getHttpStatusCode();
        echo "File Name:" . $fileResponseIns->getFileName();
        $stream = $fileResponseIns->getFileContent();
        fputs($fp, $stream);
        fclose($fp);
    }            echo $attchmentIns->getParentModule(); // To get the note's attachment parent module name
            $parentRecord = $attchmentIns->getParentRecord();
            echo $parentRecord->getEntityId(); // To get the note's parent record id
            echo $attchmentIns->getParentName(); // To get the note name
            echo $attchmentIns->getParentId(); // To get the note id
            $createdBy = $attchmentIns->getCreatedBy();
            echo $createdBy->getId(); // To get user_id who created the note's attachment
            echo $createdBy->getName(); // To get user name who created the note's attachment
            $modifiedBy = $attchmentIns->getModifiedBy();
            echo $modifiedBy->getId(); // To get user_id who modified the note's attachment
            echo $modifiedBy->getName(); // To get user name who modified the note's attachment
            $owner = $attchmentIns->getOwner();
echo $owner->getId(); // To get the note's attachment owner id
            echo $attchmentIns->getCreatedTime(); // To get attachment created time
            echo $attchmentIns->getModifiedTime(); // To get attachment modified time
        }
    }
    }
$obj =new Note();
$obj->downloadAttachmentFromNote();
 
Delete Attachment from a Note
              
              
<?php
    use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
    require 'vendor/autoload.php';
    class Note{
        public function __construct()
        {
            $configuration = array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
            ZCRMRestClient::initialize($configuration);
        }
        
public function deleteAttachmentFromNote()
    {
        $noteIns = ZCRMNote::getInstance(null, "3524033000003358002"); // to get the note instance
        $fileResponseIns = $noteIns->deleteAttachment("3524033000003393001");
        echo "HTTP Status Code:" . $fileResponseIns->getHttpStatusCode(); // To get http response code
        echo "Status:" . $fileResponseIns->getStatus(); // To get response status
        echo "Message:" . $fileResponseIns->getMessage(); // To get response message
        echo "Code:" . $fileResponseIns->getCode(); // To get status code
        echo "Details:" . $fileResponseIns->getDetails()['id'];
    }
    }
$obj =new Note();
$obj->deleteAttachmentFromNote();