Skip to content

Commit

Permalink
Merge pull request #93 from SirPoot-/master
Browse files Browse the repository at this point in the history
This PR adds in a process for getting attachments from Autotask
  • Loading branch information
reynolek authored Jan 12, 2018
2 parents 5a1e099 + b930434 commit b79a540
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
35 changes: 35 additions & 0 deletions get_attachment_example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
require_once __DIR__ . '/autoload.php';

use \ATWS;
use \ATWS\AutotaskObjects;

$username = 'INSERT USERNAME HERE';
$password = 'INSERT PASSWORD HERE';

$postAuthOpts = array(
'login' => $username,
'password' => $password,
'trace' => 1, // Allows us to debug by getting the XML requests sent
);

$opts = array('trace' => 1);
$authWsdl = 'https://webservices.autotask.net/atservices/1.5/atws.wsdl';
$client = new ATWS\Client($authWsdl, $opts);
$zoneInfo = $client->getZoneInfo($username);

$wsdl = str_replace('.asmx', '.wsdl', $zoneInfo->getZoneInfoResult->URL);
$client = new ATWS\Client($wsdl, $postAuthOpts);

$ticketId = 225975;
$attachmentInfo = new \ATWS\AutotaskObjects\Query('AttachmentInfo');
$parentidQueryfield = new \ATWS\AutotaskObjects\QueryField('parentid');
$parentidQueryfield->addExpression('equals',$ticketId);
$attachmentInfo->addField($parentidQueryfield);
$attachments = $client->query($attachmentInfo)->queryResult->EntityResults->Entity;
$attachments = (count($attachments) > 1 ? $attachments : [$attachments]);
foreach ($attachments as $attachment)
{
$result = $client->GetAttachment($attachment);
$save = file_put_contents($result->GetAttachmentResult->Info->FullPath, $result->GetAttachmentResult->Data);
}
11 changes: 11 additions & 0 deletions src/AutotaskObjects/GetAttachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace ATWS\AutotaskObjects;

class GetAttachment
{
public $attachmentId;
public function __construct($param)
{
$this->attachmentId = $param;
}
}
7 changes: 7 additions & 0 deletions src/AutotaskObjects/GetAttachmentResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace ATWS\AutotaskObjects;

class GetAttachmentResponse
{
public $GetAttachmentResult;
}
8 changes: 8 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Client extends \SoapClient
'ExpenseItem' => 'ATWS\AutotaskObjects\ExpenseItem',
'ExpenseReport' => 'ATWS\AutotaskObjects\ExpenseReport',
'Field' => 'ATWS\AutotaskObjects\Field',
'GetAttachment' => 'ATWS\AutotaskObjects\GetAttachment',
'GetAttachmentResponse' => 'ATWS\AutotaskObjects\GetAttachmentResponse',
'getUDFInfo' => 'ATWS\AutotaskObjects\UDFParam',
'getUDFInfoResponse' => 'ATWS\AutotaskObjects\UDFInfoResponse',
'InstalledProduct' => 'ATWS\AutotaskObjects\InstalledProduct',
Expand Down Expand Up @@ -205,6 +207,12 @@ public function bulkDelete(array $objs)
return $this->_call('delete', array($deleteObjs));
}

public function GetAttachment(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\GetAttachment($obj);
return $this->_call('GetAttachment', array($params));
}

public function CreateAttachment(AutotaskObjects\Entity $obj)
{
$params = new AutotaskObjects\CreateAttachment($obj);
Expand Down

0 comments on commit b79a540

Please sign in to comment.