|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Thomas Klein, All rights reserved. |
| 4 | + * See LICENSE bundled with this library for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +include __DIR__ . '/../../../vendor/autoload.php'; |
| 9 | + |
| 10 | +use Zoho\Desk\Api\Metadata; |
| 11 | +use Zoho\Desk\Client\ConfigProviderBuilder; |
| 12 | +use Zoho\Desk\Exception\CouldNotDeleteException; |
| 13 | +use Zoho\Desk\Exception\CouldNotReadException; |
| 14 | +use Zoho\Desk\Exception\CouldNotSaveException; |
| 15 | +use Zoho\Desk\Gateway; |
| 16 | +use Zoho\Desk\Model\ListCriteria; |
| 17 | +use Zoho\Desk\Model\ListCriteriaBuilder; |
| 18 | +use Zoho\OAuth\ZohoOAuth; |
| 19 | + |
| 20 | +// Optional, it's used by the zoho/oauth package |
| 21 | +define('LOGGER_PATH', __DIR__ . '/'); |
| 22 | + |
| 23 | +$configBuilder = ConfigProviderBuilder::getInstance(); |
| 24 | +$configBuilder->setClientId('1000.51C3ETBOWTOA03UL19U5EMV0F74VQR') |
| 25 | + ->setClientSecret('4086937c603d0e174ee58d5b6d9b21fb6b93802fd8') |
| 26 | + ->setRedirectUrl('') |
| 27 | + -> setCurrentUserEmail( '[email protected]') |
| 28 | + ->setApiBaseUrl(Metadata::API_ENDPOINT_EU) |
| 29 | + ->setApiVersion(Metadata::API_VERSION) |
| 30 | + ->setOrgId(20076919967) |
| 31 | + ->setIsSandbox(false) |
| 32 | + ->setAccountsUrl(Metadata::API_ACCOUNTS_EU) |
| 33 | + ->setTokenPersistencePath(__DIR__); |
| 34 | + |
| 35 | +$config = $configBuilder->create(); |
| 36 | +$gateway = new Gateway($config); |
| 37 | + |
| 38 | +// Optional: if you need to register the token first |
| 39 | +// ZohoOAuth::initialize($config->get()); |
| 40 | +// ZohoOAuth::getClientInstance()->generateAccessToken('1000.125d9d14ca4c42d8c3be5164d19433a8.c6c3be950b0290639f5126f5d9ff810b'); |
| 41 | + |
| 42 | + |
| 43 | +try { |
| 44 | + $criteriaBuilder = new ListCriteriaBuilder(); |
| 45 | + $criteriaBuilder->setFields(['id','subject', 'email', 'description','webUrl']); |
| 46 | + // $criteriaBuilder->setFields()->setFilters()... |
| 47 | + $ticketList = $gateway->getOperationPool()->getListOperation('tickets')->getList($criteriaBuilder->create()); |
| 48 | + //$ticketList = $gateway->getOperationPool()->getListOperation('tickets')->getByIds([1,2,3]); |
| 49 | +} catch (CouldNotReadException $e) { |
| 50 | + echo $e->getMessage(); |
| 51 | + echo "<br>"; |
| 52 | + echo $e->getPrevious()->getMessage(); |
| 53 | +} |
| 54 | + |
| 55 | +echo '<pre>'; |
| 56 | +foreach ($ticketList as $ticket) { |
| 57 | + echo '<hr>'; |
| 58 | + print_r($ticket->toArray()); |
| 59 | +} |
| 60 | + |
| 61 | + die; |
| 62 | + |
| 63 | +/** CRUD Operations **/ |
| 64 | + |
| 65 | +$ticketDataObject = $gateway->getDataObjectFactory()->create('tickets', /* Entity values */); |
| 66 | + |
| 67 | +try { |
| 68 | + $ticketDataObject = $gateway->getOperationPool()->getCreateOperation('tickets')->create($ticketDataObject); |
| 69 | +} catch (CouldNotSaveException $e) { |
| 70 | + // Handle the exception... |
| 71 | +} |
| 72 | + |
| 73 | +try { |
| 74 | + $ticketDataObject = $gateway->getOperationPool()->getReadOperation('tickets')->get(1234); |
| 75 | +} catch (CouldNotReadException $e) { |
| 76 | + // Handle the exception... |
| 77 | +} |
| 78 | + |
| 79 | +try { |
| 80 | + $criteriaBuilder = new ListCriteriaBuilder(); |
| 81 | + // $criteriaBuilder->setFields()->setFilters()... |
| 82 | + $ticketList = $gateway->getOperationPool()->getListOperation('tickets')->getList($criteriaBuilder->create()); |
| 83 | + $ticketList = $gateway->getOperationPool()->getListOperation('tickets')->getByIds([1,2,3]); |
| 84 | +} catch (CouldNotReadException $e) { |
| 85 | + // Handle the exception... |
| 86 | +} |
| 87 | + |
| 88 | +try { |
| 89 | + $ticketDataObject = $gateway->getOperationPool()->getUpdateOperation('tickets')->update($ticketDataObject); |
| 90 | +} catch (CouldNotSaveException $e) { |
| 91 | + // Handle the exception... |
| 92 | +} |
| 93 | + |
| 94 | +try { |
| 95 | + $gateway->getOperationPool()->getDeleteOperation('tickets', ['resolution'])->delete(1234); |
| 96 | +} catch (CouldNotDeleteException $e) { |
| 97 | + // Handle the exception... |
| 98 | +} |
0 commit comments