Skip to content

Attachments Code Examples

jfaustin edited this page Jun 19, 2012 · 4 revisions

Getting Attachments by Call Id

Attachments can be retrieved using a call Id by searching for all attachements associated with the given call Id.

/***************************************************************  
 *  
 * Example: Getting a Remedy attachment using the call Id  
 *  
 ***************************************************************/  
  
require_once 'Ncstate/Service/Remedy.php';  
  
// create a new Remedy object  
$remedy = new Ncstate_Service_Remedy($user, $pass);  
  
// the call Id must be an 8 digit number  
$callId = 00000078;  
  
try {  
    $attachments = $remedy->callAttachmentList($callId);  
} catch (Ncstate_Service_Exception $e) {  
    die('An error occured while getting the attachment:' . $e->getMessage());  
}  

if (count($attachments) > 0) {  
    print('Retrieved attachments' . $attachments);  
} else {  
    print('No attachments associated with this call');  
}  

Creating Attachments

Applications can upload and update attachments remotely using the API. All fields in an attachment object are required. Also, attachments expect data to be sent in Base64 encoding, otherwise exceptions will be thrown.

Structure of an attachment

The attachment structure is the following:

attachment_data - The attachment body. Must be Base64 encoded.
attachment_name - The name of the attachment.
attachment_size - The size of the attachment, in bytes.
call_id - The id number of the call that this attachment is to be associated with. Value must be zero-padded on the left to a length of 8 characters.
type - The attachment type (Email/Solution).
status - The attachment's status (Received/Outgoing/Sent/Hold/Solution).

Creating an attachment

/***************************************************************
 *
 * Example: Creating an attachment
 *
 ***************************************************************/  

require_once 'Ncstate/Service/Remedy.php';  
  
// create a new Remedy object
$remedy = new Ncstate_Service_Remedy($user, $pass);  
  
// a basic text attachment
$attachment = array(  
    'attachment_name' => 'Something',  
    'attachment_data' => base64_encode('Something, Something, Something...Dark side!'),  
    'type' => 'Email',  
    'status' => 'Outgoing',  
);  
$attachment['attachment_size'] = mb_strlen($this->attachment['attachment_data'], 'BASE64');  
  
try {  
    $resut = $remedy->callAttachmentCreate($callId, $attachment);  
} catch (Ncstate_Service_Exception $e) {   
    die('An error occured while creating the call:' . $e->getMessage());   
}  
  
print("Attachment has been created, it's entryId is: " . $result);  

Note on updating attachments

Updates to attachments are not supported in the current API.

Clone this wiki locally