├── .github ├── CODEOWNERS └── workflows │ └── ci.yaml ├── .gitignore ├── .tool-versions ├── .travis.yml ├── CBP_UPGRADE_GUIDE.md ├── CONTRIBUTING.md ├── Dockerfile ├── Makefile ├── README.md ├── VERSION ├── bin └── console ├── composer.json ├── composer.lock ├── docker-compose.yml ├── index.php ├── phpunit.xml.dist ├── samples ├── attachments │ ├── uploadFileAttachment.php │ └── uploadStreamAttachment.php ├── groups │ ├── createGroup.php │ └── getGroups.php ├── helpcenter │ ├── createArticles.php │ ├── createSections.php │ ├── findArticles.php │ ├── findArticlesBySectionId.php │ ├── findCategories.php │ └── findSections.php ├── organizations │ └── createOrganization.php ├── sell │ └── getContacts.php ├── ticket_fields │ ├── createDropdownOption.php │ ├── editDropdownOption.php │ └── replaceDropdownOptions.php ├── tickets │ ├── createTicket.php │ ├── createTicketWithAttachment.php │ ├── deleteTicket.php │ ├── getTicketComments.php │ ├── getTicketMetrics.php │ ├── getTickets.php │ ├── searchTickets.php │ ├── updateTicket.php │ └── viewTicket.php └── users │ ├── createUser.php │ ├── getUsers.php │ └── searchUser.php ├── src └── Zendesk │ ├── API │ ├── Debug.php │ ├── Exceptions │ │ ├── ApiResponseException.php │ │ ├── AuthException.php │ │ ├── CustomException.php │ │ ├── MissingParametersException.php │ │ ├── ResponseException.php │ │ └── RouteException.php │ ├── Http.php │ ├── HttpClient.php │ ├── Middleware │ │ └── RetryHandler.php │ ├── Resources │ │ ├── Chat.php │ │ ├── Chat │ │ │ ├── Apps.php │ │ │ └── Integrations.php │ │ ├── Core │ │ │ ├── Activities.php │ │ │ ├── AppInstallationLocations.php │ │ │ ├── AppInstallations.php │ │ │ ├── AppLocations.php │ │ │ ├── Apps.php │ │ │ ├── Attachments.php │ │ │ ├── AuditLogs.php │ │ │ ├── Autocomplete.php │ │ │ ├── Automations.php │ │ │ ├── Bookmarks.php │ │ │ ├── Brands.php │ │ │ ├── CustomRoles.php │ │ │ ├── DynamicContent.php │ │ │ ├── DynamicContentItemVariants.php │ │ │ ├── DynamicContentItems.php │ │ │ ├── GroupMemberships.php │ │ │ ├── Groups.php │ │ │ ├── Incremental.php │ │ │ ├── JobStatuses.php │ │ │ ├── Locales.php │ │ │ ├── Macros.php │ │ │ ├── OAuthClients.php │ │ │ ├── OAuthTokens.php │ │ │ ├── OrganizationFields.php │ │ │ ├── OrganizationMemberships.php │ │ │ ├── OrganizationSubscriptions.php │ │ │ ├── OrganizationTickets.php │ │ │ ├── Organizations.php │ │ │ ├── PushNotificationDevices.php │ │ │ ├── RequestComments.php │ │ │ ├── Requests.php │ │ │ ├── SatisfactionRatings.php │ │ │ ├── Search.php │ │ │ ├── Sessions.php │ │ │ ├── SharingAgreements.php │ │ │ ├── SlaPolicies.php │ │ │ ├── SupportAddresses.php │ │ │ ├── SuspendedTickets.php │ │ │ ├── Tags.php │ │ │ ├── Targets.php │ │ │ ├── TicketAudits.php │ │ │ ├── TicketComments.php │ │ │ ├── TicketFields.php │ │ │ ├── TicketFieldsOptions.php │ │ │ ├── TicketForms.php │ │ │ ├── TicketImports.php │ │ │ ├── TicketMetrics.php │ │ │ ├── Tickets.php │ │ │ ├── Translations.php │ │ │ ├── Triggers.php │ │ │ ├── TwitterHandles.php │ │ │ ├── UserFields.php │ │ │ ├── UserIdentities.php │ │ │ ├── UserTickets.php │ │ │ ├── Users.php │ │ │ ├── Views.php │ │ │ └── Webhooks.php │ │ ├── Embeddable.php │ │ ├── Embeddable │ │ │ ├── ConfigSets.php │ │ │ └── ResourceAbstract.php │ │ ├── HelpCenter.php │ │ ├── HelpCenter │ │ │ ├── Articles.php │ │ │ ├── Categories.php │ │ │ ├── ResourceAbstract.php │ │ │ └── Sections.php │ │ ├── ResourceAbstract.php │ │ ├── Sell.php │ │ ├── Sell │ │ │ ├── Contacts.php │ │ │ └── ResourceAbstract.php │ │ ├── Talk.php │ │ ├── Talk │ │ │ ├── ResourceAbstract.php │ │ │ └── Stats.php │ │ ├── Voice.php │ │ └── Voice │ │ │ ├── PhoneNumbers.php │ │ │ └── ResourceAbstract.php │ ├── Traits │ │ ├── Resource │ │ │ ├── Create.php │ │ │ ├── CreateMany.php │ │ │ ├── CreateOrUpdateMany.php │ │ │ ├── Defaults.php │ │ │ ├── Delete.php │ │ │ ├── DeleteMany.php │ │ │ ├── Find.php │ │ │ ├── FindAll.php │ │ │ ├── FindMany.php │ │ │ ├── Locales.php │ │ │ ├── MultipartUpload.php │ │ │ ├── Pagination.php │ │ │ ├── ResourceName.php │ │ │ ├── Search.php │ │ │ ├── Update.php │ │ │ └── UpdateMany.php │ │ └── Utility │ │ │ ├── ChainedParametersTrait.php │ │ │ ├── InstantiatorTrait.php │ │ │ └── Pagination │ │ │ ├── AbstractStrategy.php │ │ │ ├── CbpStrategy.php │ │ │ ├── ObpStrategy.php │ │ │ ├── PaginationError.php │ │ │ ├── PaginationIterator.php │ │ │ └── SinglePageStrategy.php │ └── Utilities │ │ ├── Auth.php │ │ └── OAuth.php │ ├── Console │ ├── ConsoleCommand.php │ ├── Matchers │ │ └── SubResourceMatcher.php │ └── Shell.php │ └── Fixtures │ └── MockResource.php ├── tests ├── Zendesk │ └── API │ │ ├── LiveTests │ │ ├── AuthTest.php │ │ ├── BasicTest.php │ │ ├── HelpCenterTest.php │ │ ├── SearchTest.php │ │ ├── TicketsTest.php │ │ └── UsersTest.php │ │ └── UnitTests │ │ ├── BasicTest.php │ │ ├── Chat │ │ ├── AppsTest.php │ │ └── IntegrationsTest.php │ │ ├── Core │ │ ├── AppInstallationLocationsTest.php │ │ ├── AppInstallationsTest.php │ │ ├── AppLocationsTest.php │ │ ├── AppsTest.php │ │ ├── AttachmentsTest.php │ │ ├── AuditLogsTest.php │ │ ├── AuthTest.php │ │ ├── AutocompleteTest.php │ │ ├── AutomationsTest.php │ │ ├── BookmarksTest.php │ │ ├── BrandsTest.php │ │ ├── CustomRolesTest.php │ │ ├── DummyResource.php │ │ ├── DynamicContentItemVariantsTest.php │ │ ├── GroupMembershipsTest.php │ │ ├── GroupsTest.php │ │ ├── IncrementalExportsTest.php │ │ ├── LocalesTest.php │ │ ├── MacrosTest.php │ │ ├── OAuthClientsTest.php │ │ ├── OAuthTokensTest.php │ │ ├── OrganizationFieldsTest.php │ │ ├── OrganizationMembershipsTest.php │ │ ├── OrganizationSubscriptionsTest.php │ │ ├── OrganizationTicketsTest.php │ │ ├── OrganizationsTest.php │ │ ├── PushNotificationDevicesTest.php │ │ ├── RequestCommentsTest.php │ │ ├── RequestsTest.php │ │ ├── ResourceTest.php │ │ ├── SatisfactionRatingsTest.php │ │ ├── SearchTest.php │ │ ├── SessionsTest.php │ │ ├── SharingAgreementsTest.php │ │ ├── SlaPoliciesTest.php │ │ ├── SupportAddressesTest.php │ │ ├── SuspendedTicketsTest.php │ │ ├── TagsTest.php │ │ ├── TicketAuditsTest.php │ │ ├── TicketCommentsTest.php │ │ ├── TicketFieldsOptionsTest.php │ │ ├── TicketFieldsTest.php │ │ ├── TicketFormsTest.php │ │ ├── TicketImportsTest.php │ │ ├── TicketMetricsTest.php │ │ ├── TicketsTest.php │ │ ├── TranslationsTest.php │ │ ├── TriggersTest.php │ │ ├── TwitterHandlesTest.php │ │ ├── UserFieldsTest.php │ │ ├── UserIdentitiesTest.php │ │ ├── UserTicketsTest.php │ │ ├── UsersTest.php │ │ ├── ViewsTest.php │ │ └── WebhooksTest.php │ │ ├── Embeddable │ │ └── ConfigSetsTest.php │ │ ├── Exceptions │ │ └── ApiResponseExceptionTest.php │ │ ├── HelpCenter │ │ ├── ArticlesTest.php │ │ ├── CategoriesTest.php │ │ └── SectionsTest.php │ │ ├── HttpTest.php │ │ ├── Middleware │ │ └── RetryHandlerTest.php │ │ ├── Sell │ │ └── ContactsTest.php │ │ ├── Talk │ │ └── StatsTest.php │ │ ├── Traits │ │ └── Utility │ │ │ └── PaginationIteratorTest.php │ │ ├── Utilities │ │ └── OAuthTest.php │ │ ├── VersionTest.php │ │ └── Voice │ │ └── PhoneNumbersTest.php ├── assets │ ├── UK.png │ ├── app.zip │ └── ga4.png └── bootstrap.php └── tmp └── .gitkeep /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @zendesk/redback 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ master, 3.x ] 6 | pull_request: 7 | branches: [ master, 3.x ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v2 16 | 17 | - name: Build Docker image 18 | run: docker build . --file Dockerfile --tag zendesk_api_client_php-app 19 | 20 | - name: Run Composer install 21 | run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app make build 22 | 23 | - name: Run lint 24 | run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app make lint 25 | 26 | - name: Run tests 27 | run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app make test 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | phpunit.xml 3 | tmp/** 4 | .phpunit.result.cache 5 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | php 8.2.27 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: php 3 | php: 4 | - 5.5 5 | - 5.6 6 | - 7.0 7 | - 7.1 8 | - 7.2 9 | - nightly 10 | matrix: 11 | fast_finish: true 12 | allow_failures: 13 | - php: 7.2 14 | - php: nightly 15 | install: 16 | - travis_retry composer self-update && composer install 17 | script: 18 | - vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites" 19 | - vendor/bin/phpcs --extensions=php --standard=PSR2 --report=summary -np src/ tests/ 20 | notifications: 21 | email: false 22 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.2-cli 2 | 3 | # OS requirements for PHP 4 | RUN apt-get update && apt-get install -y git unzip 5 | 6 | # Safe requirements to allow Makefile tasks to run 7 | RUN git config --global --add safe.directory /app 8 | 9 | # PHP requirements 10 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 11 | WORKDIR /app 12 | COPY composer.json composer.lock /app/ 13 | RUN composer install 14 | 15 | COPY . /app 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build test lint 2 | 3 | build: 4 | composer install 5 | 6 | test: 7 | composer test:unit 8 | 9 | lint: 10 | composer lint 11 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 4.1.0 2 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | add(new ConsoleCommand); 14 | $app->setDefaultCommand('console', true); 15 | $app->run(); 16 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zendesk/zendesk_api_client_php", 3 | "description": "PHP Client for Zendesk REST API. See https://developer.zendesk.com/rest_api/docs/core/introduction .", 4 | "license": "Apache-2.0", 5 | "homepage": "https://github.com/zendesk/zendesk_api_client_php", 6 | "require": { 7 | "php": ">=8.2.0", 8 | "guzzlehttp/guzzle": "^6.0 || ^7.0", 9 | "guzzlehttp/psr7": "^1.7 || ^2.0", 10 | "mmucklo/inflect": "0.3.*" 11 | }, 12 | "require-dev": { 13 | "phpunit/phpunit": "11.5.0", 14 | "squizlabs/php_codesniffer": "3.*", 15 | "phpmd/phpmd": "@stable", 16 | "fakerphp/faker": "^1.24.1", 17 | "psy/psysh": "@stable" 18 | }, 19 | "autoload": { 20 | "psr-0": { 21 | "Zendesk\\API\\": "src/", 22 | "Zendesk\\Console\\": "src/", 23 | "Zendesk\\Fixtures\\": "src/" 24 | } 25 | }, 26 | "scripts": { 27 | "test:unit": "vendor/bin/phpunit --testsuite 'Zendesk API Unit Test Suites'", 28 | "test:live": "vendor/bin/phpunit --testsuite 'Zendesk API Live Test Suites'", 29 | "lint": "vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1 --standard=PSR12 --extensions=php --ignore=vendor/ .", 30 | "lint:fix": "vendor/bin/phpcbf --runtime-set ignore_warnings_on_exit 1 --standard=PSR12 --extensions=php --ignore=vendor/ ." 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | app: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | volumes: 8 | - .:/app 9 | - vendor:/app/vendor 10 | command: vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites" 11 | # command: vendor/bin/phpunit --testdox --testsuite "Zendesk API Unit Test Suites" 12 | # command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/Traits/Utility/PaginationIteratorTest.php 13 | # command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/Core/TicketsTest.php 14 | # command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/HttpTest.php 15 | # command: vendor/bin/phpunit --testsuite "Zendesk API Live Test Suites" 16 | 17 | volumes: 18 | vendor: 19 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ./tests/Zendesk/API/UnitTests 21 | ./tests/Zendesk/API/UnitTests/BasicTest.php 22 | 23 | 24 | ./tests/Zendesk/API/LiveTests 25 | ./tests/Zendesk/API/LiveTests/BasicTest.php 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /samples/attachments/uploadFileAttachment.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Upload an existing file attachment. 20 | $attachment = $client->attachments()->upload(array( 21 | 'file' => '../../tests/assets/UK.png', 22 | 'type' => 'image/png', 23 | 'name' => 'UK test non-alpha chars.png' 24 | )); 25 | 26 | // Show result 27 | echo "
";
28 |     print_r($attachment);
29 |     echo "
"; 30 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 31 | echo $e->getMessage() . '
'; 32 | } 33 | -------------------------------------------------------------------------------- /samples/attachments/uploadStreamAttachment.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 18 | 19 | try { 20 | // Upload a dynamically created file stream. 21 | $attachment = $client->attachments()->upload(array( 22 | 'file' => new LazyOpenStream('../../tests/assets/UK.png', 'r'), 23 | 'type' => 'image/png', 24 | 'name' => 'UK test non-alpha chars.png' 25 | )); 26 | 27 | // Show result 28 | echo "
";
29 |     print_r($attachment);
30 |     echo "
"; 31 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 32 | echo $e->getMessage() . '
'; 33 | } 34 | -------------------------------------------------------------------------------- /samples/groups/createGroup.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | $newGroup = $client->groups()->create(array( 20 | 'name' => '2d line', 21 | )); 22 | 23 | // Show result 24 | echo "
";
25 |     print_r($newGroup);
26 |     echo "
"; 27 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 28 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 29 | } 30 | -------------------------------------------------------------------------------- /samples/groups/getGroups.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | $query = $client->groups()->findAll(); 20 | foreach ($query as $UserData) { 21 | echo "
";
22 |         print_r($UserData);
23 |         echo "
"; 24 | } 25 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 26 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 27 | } 28 | -------------------------------------------------------------------------------- /samples/helpcenter/createArticles.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Create a new HelpCenter Article 20 | $sectionId = 1; 21 | $article = $client->helpCenter->sections($sectionId)->articles()->create([ 22 | 'locale' => 'en-us', 23 | 'title' => 'Smartest Fish in the World', 24 | ]); 25 | echo "
";
26 |     print_r($article);
27 |     echo "
"; 28 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 29 | echo $e->getMessage() . '
'; 30 | } 31 | -------------------------------------------------------------------------------- /samples/helpcenter/createSections.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Create a new HelpCenter Section 20 | $categoryId = 1; 21 | $section = $client->helpCenter->categories($categoryId)->sections()->create([ 22 | 'position' => 1, 23 | 'locale' => 'en-us', 24 | 'name' => 'Super Hero Tricks', 25 | 'description' => 'This section contains a collection of super hero tricks', 26 | ]); 27 | echo "
";
28 |     print_r($section);
29 |     echo "
"; 30 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 31 | echo $e->getMessage() . '
'; 32 | } 33 | -------------------------------------------------------------------------------- /samples/helpcenter/findArticles.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | $help_center_client = new Zendesk\API\Resources\HelpCenter($client); 18 | 19 | try { 20 | // Find all helpcenter categories 21 | $articles = $help_center_client->articles()->findAll(); 22 | 23 | echo "
";
24 |     print_r($articles);
25 |     echo "
"; 26 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 27 | echo $e->getMessage() . '
'; 28 | } 29 | -------------------------------------------------------------------------------- /samples/helpcenter/findArticlesBySectionId.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 18 | $help_center_client = new Zendesk\API\Resources\HelpCenter($client); 19 | 20 | try { 21 | // Find all helpcenter category with the given section id 22 | $articles = $help_center_client->sections($section_id)->articles()->findAll(); 23 | 24 | echo "
";
25 |     print_r($articles);
26 |     echo "
"; 27 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 28 | echo $e->getMessage() . '
'; 29 | } 30 | -------------------------------------------------------------------------------- /samples/helpcenter/findCategories.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Find all helpcenter categories 20 | $categories = $client->helpCenter->categories()->findAll(); 21 | 22 | echo "
";
23 |     print_r($categories);
24 |     echo "
"; 25 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 26 | echo $e->getMessage() . '
'; 27 | } 28 | -------------------------------------------------------------------------------- /samples/helpcenter/findSections.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Find all helpcenter sections 20 | $sections = $client->helpCenter->sections()->findAll(); 21 | echo "
";
22 |     print_r($sections);
23 |     echo "
"; 24 | 25 | // Find all helpcenter sections with a specific locale 26 | $sections = $client->helpCenter->sections()->setLocale('en-us')->findAll(); 27 | echo "
";
28 |     print_r($sections);
29 |     echo "
"; 30 | 31 | // Find all helpcenter sections within a specific category 32 | $categoryId = 204009948; 33 | $sections = $client->helpCenter->categories($categoryId)->sections()->findAll(); 34 | echo "
";
35 |     print_r($sections);
36 |     echo "
"; 37 | 38 | // Find all helpcenter sections with a specific locale in a category 39 | $sections = $client->helpCenter->categories($categoryId)->sections()->setLocale('en-us')->findAll(); 40 | echo "
";
41 |     print_r($sections);
42 |     echo "
"; 43 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 44 | echo $e->getMessage() . '
'; 45 | } 46 | -------------------------------------------------------------------------------- /samples/organizations/createOrganization.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 14 | try { 15 | $newOrganization = $client->organizations()->create( 16 | [ 17 | 'external_id' => '123567854', 18 | 'name' => 'Example_Organization', 19 | 'shared_tickets' => 1, 20 | 'shared_comments' => 1, 21 | 'tags' => array('dog', 'cat', 'fish', 'strange_creature'), 22 | 'organization_fields' => array('favorite animal' => 'fish') 23 | ] 24 | ); 25 | // Show result 26 | echo "
";
27 |     print_r($newOrganization);
28 |     echo "
"; 29 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 30 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 31 | } 32 | -------------------------------------------------------------------------------- /samples/sell/getContacts.php: -------------------------------------------------------------------------------- 1 | setAuth('oauth', ['token' => $token]); 16 | $sell_client = new Zendesk\API\Resources\Sell($client); 17 | 18 | try { 19 | // Find all sell contacts 20 | $contacts = $sell_client->contacts()->findAll(); 21 | 22 | echo "
";
23 |     print_r($contacts);
24 |     echo "
"; 25 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 26 | echo $e->getMessage() . '
'; 27 | } 28 | -------------------------------------------------------------------------------- /samples/ticket_fields/createDropdownOption.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 14 | try { 15 | $result = $client->ticketFields(51931448)->options()->create( 16 | ['name' => 'beetle', 17 | 'value' => 'beetle'] 18 | ); 19 | // Show result 20 | echo "
";
21 |     print_r($newOrganization);
22 |     echo "
"; 23 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 24 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 25 | } 26 | -------------------------------------------------------------------------------- /samples/ticket_fields/editDropdownOption.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 14 | try { 15 | $result = $client->ticketFields(51931448)->options()->update( 16 | 360000992534, 17 | ['name' => 'notfrog', 18 | 'value' => 'notfrog'] 19 | ); 20 | // Show result 21 | echo "
";
22 |     print_r($newOrganization);
23 |     echo "
"; 24 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 25 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 26 | } 27 | -------------------------------------------------------------------------------- /samples/ticket_fields/replaceDropdownOptions.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 14 | try { 15 | $result = $client->ticketFields()->update(51931448, ["custom_field_options" => [ 16 | [ 17 | "name" => "Apple Pie", 18 | "value" => "apple_pie" 19 | ], 20 | [ 21 | "name" => "Pecan Pie", 22 | "value" => "pecan_pie" 23 | ] 24 | ] 25 | ]); 26 | // Show result 27 | echo "
";
28 |     print_r($newOrganization);
29 |     echo "
"; 30 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 31 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 32 | } 33 | -------------------------------------------------------------------------------- /samples/tickets/createTicket.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 16 | 17 | try { 18 | // Create a new ticket 19 | $newTicket = $client->tickets()->create([ 20 | 'type' => 'problem', 21 | 'tags' => array('demo', 'testing', 'api', 'zendesk'), 22 | 'subject' => 'The quick brown fox jumps over the lazy dog', 23 | 'comment' => array( 24 | 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' 25 | ), 26 | 'requester' => array( 27 | 'locale_id' => '1', 28 | 'name' => 'Example User', 29 | 'email' => 'customer@example.com', 30 | ), 31 | 'priority' => 'normal', 32 | ]); 33 | 34 | // Show result 35 | echo "
";
36 |     print_r($newTicket);
37 |     echo "
"; 38 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 39 | echo $e->getMessage() . '
'; 40 | } 41 | -------------------------------------------------------------------------------- /samples/tickets/createTicketWithAttachment.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 18 | 19 | try { 20 | // Upload file 21 | $attachment = $client->attachments()->upload([ 22 | 'file' => $attachment, 23 | 'type' => 'image/jpg', 24 | 'name' => 'sample.jpg' 25 | ]); 26 | 27 | // Create a new ticket with attachment 28 | $newTicket = $client->tickets()->create([ 29 | 'type' => 'problem', 30 | 'tags' => array('demo', 'testing', 'api', 'zendesk'), 31 | 'subject' => 'The quick brown fox jumps over the lazy dog', 32 | 'comment' => array( 33 | 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 34 | 'uploads' => [$attachment->upload->token] 35 | ), 36 | 'requester' => array( 37 | 'locale_id' => '1', 38 | 'name' => 'Example User', 39 | 'email' => 'customer@example.com', 40 | ), 41 | 'priority' => 'normal', 42 | ]); 43 | 44 | // Show result 45 | echo "
";
46 |     print_r($newTicket);
47 |     echo "
"; 48 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 49 | echo $e->getMessage() . '
'; 50 | } 51 | -------------------------------------------------------------------------------- /samples/tickets/deleteTicket.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Delete a ticket by id 20 | $id = 1; 21 | $deleteTicket = $client->tickets()->delete($id); 22 | echo "Ticket ($id) has been removed"; 23 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 24 | echo $e->getMessage() . '
'; 25 | } 26 | -------------------------------------------------------------------------------- /samples/tickets/getTicketComments.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Query the Zendesk API to retrieve the ticket comments 20 | $id = 1; 21 | $tickets = $client->tickets($id)->comments()->findAll(); 22 | 23 | // Show the results 24 | echo "
";
25 |     print_r($tickets);
26 |     echo "
"; 27 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 28 | echo $e->getMessage() . '
'; 29 | } 30 | -------------------------------------------------------------------------------- /samples/tickets/getTicketMetrics.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Find all metrics for a given ticket 20 | $id = 1; 21 | $metrics = $client->tickets($id)->metrics()->findAll(); 22 | 23 | echo "
";
24 |     print_r($metrics);
25 |     echo "
"; 26 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 27 | echo $e->getMessage() . '
'; 28 | } 29 | -------------------------------------------------------------------------------- /samples/tickets/getTickets.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Get all tickets 20 | $tickets = $client->tickets()->findAll(); 21 | 22 | // Show the results 23 | echo "
";
24 |     print_r($tickets);
25 |     echo "
"; 26 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 27 | echo $e->getMessage() . '
'; 28 | } 29 | -------------------------------------------------------------------------------- /samples/tickets/searchTickets.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Search the current customer 20 | $params = ['query' => 'customer@example.com']; 21 | $search = $client->users()->search($params); 22 | 23 | if (empty($search->users)) { 24 | echo "This email address could not be found on Zendesk"; 25 | } else { 26 | foreach ($search->users as $userData) { 27 | $userId = $userData->id; 28 | $tickets = $client->users($userId)->requests()->findAll(); 29 | 30 | // Show the results 31 | echo "
";
32 |             print_r($tickets);
33 |             echo "
"; 34 | } 35 | } 36 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 37 | echo $e->getMessage() . '
'; 38 | } 39 | -------------------------------------------------------------------------------- /samples/tickets/updateTicket.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Update a new ticket 20 | $updateTicket = $client->tickets()->update(1, [ 21 | 'priority' => 'urgent', 22 | 'comment' => [ 23 | 'body' => 'We have changed your ticket priority to Urgent and will keep you up-to-date asap.' 24 | ], 25 | ]); 26 | 27 | // Show result 28 | echo "
";
29 |     print_r($updateTicket);
30 |     echo "
"; 31 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 32 | echo $e->getMessage() . '
'; 33 | } 34 | -------------------------------------------------------------------------------- /samples/tickets/viewTicket.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Query Zendesk API to retrieve the ticket details 20 | 21 | $id = 1; 22 | $tickets = $client->tickets()->find($id); 23 | 24 | // Show the results 25 | echo "
";
26 |     print_r($tickets->ticket);
27 |     echo "
"; 28 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 29 | echo $e->getMessage() . '
'; 30 | } 31 | -------------------------------------------------------------------------------- /samples/users/createUser.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | $query = $client->users()->create( 20 | [ 21 | 'name' => 'API Demo', 22 | 'email' => 'demo@example.com', 23 | 'phone' => '+1-954-704-6031', 24 | 'role' => 'end-user', 25 | 'details' => 'This user has been created with the API.' 26 | ] 27 | ); 28 | 29 | echo "
";
30 |     print_r($query);
31 |     echo "
"; 32 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 33 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 34 | } 35 | -------------------------------------------------------------------------------- /samples/users/getUsers.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | $query = $client->users()->findAll(); 20 | foreach ($query->users as $UserData) { 21 | echo "
";
22 |         print_r($UserData);
23 |         echo "
"; 24 | } 25 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 26 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 27 | } 28 | -------------------------------------------------------------------------------- /samples/users/searchUser.php: -------------------------------------------------------------------------------- 1 | setAuth('basic', ['username' => $username, 'token' => $token]); 17 | 18 | try { 19 | // Search the current customer 20 | $params = array('query' => 'demo@example.com'); 21 | $search = $client->users()->search($params); 22 | // verify if this email address exists 23 | if (empty($search->users)) { 24 | echo 'This email adress could not be found on Zendesk.'; 25 | } else { 26 | foreach ($search->users as $UserData) { 27 | echo "
";
28 |             print_r($UserData);
29 |             echo "
"; 30 | } 31 | } 32 | } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { 33 | echo 'Please check your credentials. Make sure to change the $subdomain, $username, and $token variables in this file.'; 34 | } 35 | -------------------------------------------------------------------------------- /src/Zendesk/API/Debug.php: -------------------------------------------------------------------------------- 1 | lastResponseError; 37 | if (! is_string($lastError)) { 38 | $lastError = json_encode($lastError); 39 | } 40 | $output = 'LastResponseCode: ' . $this->lastResponseCode 41 | . ', LastResponseError: ' . $lastError 42 | . ', LastResponseHeaders: ' . json_encode($this->lastResponseHeaders) 43 | . ', LastRequestHeaders: ' . json_encode($this->lastRequestHeaders) 44 | . ', LastRequestBody: ' . $this->lastRequestBody; 45 | 46 | return $output; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Zendesk/API/Exceptions/ApiResponseException.php: -------------------------------------------------------------------------------- 1 | getMessage(); 24 | 25 | if ($e instanceof ClientException) { 26 | $response = $e->getResponse(); 27 | $responseBody = $response->getBody()->getContents(); 28 | $this->errorDetails = $responseBody; 29 | $message .= ' [details] ' . $this->errorDetails; 30 | } elseif ($e instanceof ServerException) { 31 | $message .= ' [details] Zendesk may be experiencing internal issues or undergoing scheduled maintenance.'; 32 | } elseif (! $e->hasResponse()) { 33 | $request = $e->getRequest(); 34 | // Unsuccessful response, log what we can 35 | $message .= ' [url] ' . $request->getUri(); 36 | $message .= ' [http method] ' . $request->getMethod(); 37 | $message .= ' [body] ' . $request->getBody()->getContents(); 38 | } 39 | 40 | parent::__construct($message, $e->getCode(), $e); 41 | } 42 | 43 | /** 44 | * Returns an array of error fields with descriptions. 45 | * 46 | * { 47 | * "email": [{ 48 | * "description": "Email: roge@example.org is already being used by another user", 49 | * "error": "DuplicateValue" 50 | * }], 51 | * "external_id":[{ 52 | * "description": "External has already been taken", 53 | * "error": "DuplicateValue" 54 | * }] 55 | * } 56 | * 57 | * @return array 58 | */ 59 | public function getErrorDetails() 60 | { 61 | return $this->errorDetails; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Zendesk/API/Exceptions/AuthException.php: -------------------------------------------------------------------------------- 1 | getDebug() for details' . $detail, 22 | $code, 23 | $previous 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Zendesk/API/Exceptions/RouteException.php: -------------------------------------------------------------------------------- 1 | client->chat 13 | * 14 | * @method Apps apps() 15 | */ 16 | class Chat 17 | { 18 | use ChainedParametersTrait; 19 | use InstantiatorTrait; 20 | 21 | public $client; 22 | 23 | /** 24 | * Sets the client to be used 25 | * 26 | * @param HttpClient $client 27 | */ 28 | public function __construct(HttpClient $client) 29 | { 30 | $this->client = $client; 31 | } 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | public static function getValidSubResources() 37 | { 38 | return [ 39 | 'apps' => Apps::class, 40 | 'integrations' => Integrations::class, 41 | ]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Chat/Apps.php: -------------------------------------------------------------------------------- 1 | setRoutes( 27 | [ 28 | 'install' => "{$this->resourceName}/installations.json", 29 | ] 30 | ); 31 | } 32 | 33 | /** 34 | * Installs a Chat App on the account. app_id is required, as is a settings hash containing keys for all required 35 | * parameters for the app. 36 | * Any values in settings that don't correspond to a parameter that the app declares will be silently ignored. 37 | * 38 | * @param array $params 39 | * 40 | * @return \stdClass | null 41 | */ 42 | public function install(array $params) 43 | { 44 | return $this->client->post($this->getRoute(__FUNCTION__), $params); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Chat/Integrations.php: -------------------------------------------------------------------------------- 1 | setRoutes( 23 | [ 24 | 'find' => 'zopim_integration.json', 25 | ] 26 | ); 27 | } 28 | 29 | /** 30 | * Find the ChatAccount integrated to a Zendesk account 31 | * 32 | * @return \stdClass | null 33 | */ 34 | public function find() 35 | { 36 | return $this->client->get($this->getRoute(__FUNCTION__)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Activities.php: -------------------------------------------------------------------------------- 1 | setRoute('reorder', "{$this->resourceName}/reorder.json"); 31 | } 32 | 33 | /** 34 | * Creates or updates the relevant Location Installation record with the installation order specified 35 | * 36 | * @param array $params 37 | * 38 | * @return \stdClass | null 39 | * @throws \Zendesk\API\Exceptions\RouteException 40 | */ 41 | public function reorder(array $params) 42 | { 43 | return $this->client->post($this->getRoute(__FUNCTION__), $params); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/AppLocations.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 25 | 'findAll' => "{$this->resourceName}.json", 26 | 'find' => "{$this->resourceName}/{id}.json", 27 | ]); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function findAll(array $params = []) 34 | { 35 | $queryParams = array_filter(array_flip($params), [$this, 'filterParams']); 36 | $queryParams = array_merge($params, array_flip($queryParams)); 37 | 38 | return $this->traitFindAll($queryParams); 39 | } 40 | 41 | /** 42 | * Filter parameters passed and only allow valid query parameters. 43 | * 44 | * @param $param 45 | * @return int 46 | */ 47 | private function filterParams($param) 48 | { 49 | return preg_match("/^sort_by|sort_order|filter[[a-zA-Z_]*](\\[\\]?)/", $param); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Autocomplete.php: -------------------------------------------------------------------------------- 1 | setRoute('tags', 'autocomplete/tags.json'); 18 | } 19 | 20 | /** 21 | * Submits a request for matching tags 22 | * 23 | * @param array $params 24 | * 25 | * @throws \Exception 26 | * @return \stdClass | null 27 | */ 28 | public function tags(array $params) 29 | { 30 | $this->client->get($this->getRoute(__FUNCTION__), $params); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Automations.php: -------------------------------------------------------------------------------- 1 | setRoute('findActive', "{$this->resourceName}/active.json"); 23 | } 24 | 25 | /** 26 | * List all active Automations 27 | * 28 | * @param array $params 29 | * 30 | * @throws \Exception 31 | * @return \stdClass | null 32 | */ 33 | public function findActive(array $params = []) 34 | { 35 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Bookmarks.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 26 | 'checkHostMapping' => "{$this->resourceName}/check_host_mapping.json", 27 | 'updateImage' => "{$this->resourceName}/{id}.json", 28 | ]); 29 | } 30 | 31 | /** 32 | * Check host mapping validity 33 | * 34 | * @param array $params 35 | * 36 | * @return \stdClass | null 37 | * @throws \Zendesk\API\Exceptions\RouteException 38 | */ 39 | public function checkHostMapping(array $params = []) 40 | { 41 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | public function getUploadName() 48 | { 49 | return 'brand[photo][uploaded_data]'; 50 | } 51 | 52 | /** 53 | * {$@inheritdoc} 54 | */ 55 | public function getUploadRequestMethod() 56 | { 57 | return 'PUT'; 58 | } 59 | 60 | /** 61 | * Update a brand's image 62 | * 63 | * @param array $params 64 | * 65 | * @return \stdClass | null 66 | */ 67 | public function updateImage(array $params = []) 68 | { 69 | $this->setAdditionalRouteParams(['id' => $this->getChainedParameter(self::class)]); 70 | 71 | return $this->upload($params, __FUNCTION__); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/CustomRoles.php: -------------------------------------------------------------------------------- 1 | DynamicContentItems::class, 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/DynamicContentItemVariants.php: -------------------------------------------------------------------------------- 1 | setRoutes( 43 | [ 44 | 'findAll' => 'dynamic_content/items/{item_id}/variants.json', 45 | 'find' => 'dynamic_content/items/{item_id}/variants/{id}.json', 46 | 'create' => 'dynamic_content/items/{item_id}/variants.json', 47 | 'delete' => 'dynamic_content/items/{item_id}/variants.json', 48 | 'update' => 'dynamic_content/items/{item_id}/variants/{id}.json', 49 | 'createMany' => 'dynamic_content/items/{item_id}/variants/create_many.json', 50 | 'updateMany' => 'dynamic_content/items/{item_id}/variants/update_many.json', 51 | ] 52 | ); 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | public function getRoute($name, array $params = []) 59 | { 60 | $params = $this->addChainedParametersToParams($params, ['item_id' => DynamicContentItems::class]); 61 | 62 | return parent::getRoute($name, $params); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/DynamicContentItems.php: -------------------------------------------------------------------------------- 1 | DynamicContentItemVariants::class, 41 | ]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Groups.php: -------------------------------------------------------------------------------- 1 | GroupMemberships::class, 27 | ]; 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | protected function setUpRoutes() 34 | { 35 | parent::setUpRoutes(); 36 | $this->setRoute('assignable', 'groups/assignable.json'); 37 | } 38 | 39 | /** 40 | * Returns a route and replaces tokenized parts of the string with 41 | * the passed params 42 | * 43 | * @param $name 44 | * @param array $params 45 | * 46 | * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats 47 | * based on the parent chain 48 | * GET /api/v2/groups.json 49 | * GET /api/v2/users/{user_id}/groups.json 50 | * 51 | * @throws \Exception 52 | */ 53 | public function getRoute($name, array $params = []) 54 | { 55 | $lastChained = $this->getLatestChainedParameter(); 56 | 57 | $chainedResourceNames = array_keys($lastChained); 58 | 59 | if (empty($lastChained) || $name !== 'findAll') { 60 | return parent::getRoute($name, $params); 61 | } else { 62 | $id = reset($lastChained); 63 | $resource = (new $chainedResourceNames[0]($this->client))->resourceName; 64 | 65 | if ('users' === $resource) { 66 | return "users/$id/groups.json"; 67 | } else { 68 | return 'groups.json'; 69 | } 70 | } 71 | } 72 | 73 | /** 74 | * Show assignable groups 75 | * 76 | * @return \stdClass | null 77 | */ 78 | public function assignable() 79 | { 80 | return $this->client->get($this->getRoute(__FUNCTION__)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Incremental.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 19 | 'tickets' => "{$this->resourceName}/tickets.json", 20 | 'ticketEvents' => "{$this->resourceName}/ticket_events.json", 21 | 'organizations' => "{$this->resourceName}/organizations.json", 22 | 'users' => "{$this->resourceName}/users.json", 23 | ]); 24 | } 25 | 26 | /** 27 | * Incremental Ticket Export 28 | * 29 | * @param array $params 30 | * 31 | * @return \stdClass | null 32 | * @throws \Zendesk\API\Exceptions\RouteException 33 | */ 34 | public function tickets(array $params) 35 | { 36 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 37 | } 38 | 39 | /** 40 | * The Ticket Events Incremental Export API returns a an stream changes that have occurred on tickets. 41 | * 42 | * @param array $params 43 | * 44 | * @return \stdClass | null 45 | * @throws \Zendesk\API\Exceptions\RouteException 46 | */ 47 | public function ticketEvents(array $params) 48 | { 49 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 50 | } 51 | 52 | /** 53 | * Get information about organizations updated since a given point in time 54 | * 55 | * @param array $params 56 | * 57 | * @return \stdClass | null 58 | * @throws \Zendesk\API\Exceptions\RouteException 59 | */ 60 | public function organizations(array $params) 61 | { 62 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 63 | } 64 | 65 | /** 66 | * Get information about users updated since a given point in time 67 | * 68 | * @param array $params 69 | * 70 | * @return \stdClass | null 71 | * @throws \Zendesk\API\Exceptions\RouteException 72 | */ 73 | public function users(array $params) 74 | { 75 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/JobStatuses.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 23 | 'findAllPublic' => "{$this->resourceName}/public.json", 24 | 'findAllAgent' => "{$this->resourceName}/agent.json", 25 | 'findCurrent' => "{$this->resourceName}/current.json", 26 | 'findBest' => "{$this->resourceName}/detect_best_locale.json", 27 | ]); 28 | } 29 | 30 | /** 31 | * This lists the translation locales that are available to all accounts 32 | * 33 | * @param array $params 34 | * 35 | * @throws \Exception 36 | * 37 | * @return \stdClass | null 38 | */ 39 | public function findAllPublic(array $params = []) 40 | { 41 | return $this->findAll($params, __FUNCTION__); 42 | } 43 | 44 | /** 45 | * This lists the translation locales that have been localized for agents. 46 | * 47 | * @param array $params 48 | * 49 | * @throws \Exception 50 | * 51 | * @return \stdClass | null 52 | */ 53 | public function findAllAgent(array $params = []) 54 | { 55 | return $this->findAll($params, __FUNCTION__); 56 | } 57 | 58 | /** 59 | * This works exactly like show, but instead of taking an id as argument, 60 | * it renders the locale of the user performing the request 61 | * 62 | * @param array $params 63 | * 64 | * @throws \Exception 65 | * 66 | * @return \stdClass | null 67 | */ 68 | public function findCurrent(array $params = []) 69 | { 70 | return $this->findAll($params, __FUNCTION__); 71 | } 72 | 73 | /** 74 | * Detect best language for user 75 | * 76 | * @param array $params 77 | * 78 | * @throws \Exception 79 | * 80 | * @return \stdClass | null 81 | */ 82 | public function findBest(array $params = []) 83 | { 84 | return $this->findAll($params, __FUNCTION__); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/OAuthClients.php: -------------------------------------------------------------------------------- 1 | setRoute('findAllMine', 'users/me/oauth/clients.json'); 31 | } 32 | 33 | /** 34 | * Find all oauth clients belonging to the logged in user. 35 | * 36 | * @param array $params 37 | * 38 | * @return \stdClass | null 39 | */ 40 | public function findAllMine(array $params = []) 41 | { 42 | return $this->findAll($params, __FUNCTION__); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/OAuthTokens.php: -------------------------------------------------------------------------------- 1 | setRoute('current', "$this->resourceName/current.json"); 36 | } 37 | 38 | /** 39 | * Wrapper for `delete`, called `revoke` in the API docs. 40 | * 41 | * @param null $id 42 | * 43 | * @return bool 44 | * @throws \Zendesk\API\Exceptions\MissingParametersException 45 | */ 46 | public function revoke($id = null) 47 | { 48 | return $this->delete($id, 'delete'); 49 | } 50 | 51 | /** 52 | * Shows the current token 53 | * 54 | * @return \stdClass | null 55 | * @throws \Zendesk\API\Exceptions\RouteException 56 | */ 57 | public function current() 58 | { 59 | return $this->client->get($this->getRoute(__FUNCTION__)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/OrganizationFields.php: -------------------------------------------------------------------------------- 1 | setRoute('reorder', 'organization_fields/reorder.json'); 25 | } 26 | 27 | /** 28 | * Reorder organization fields 29 | * 30 | * @param array $params 31 | * 32 | * @throws MissingParametersException 33 | * @throws \Exception 34 | * 35 | * @return \stdClass | null 36 | */ 37 | public function reorder(array $params) 38 | { 39 | if (! $this->hasKeys($params, ['organization_field_ids'])) { 40 | throw new MissingParametersException(__METHOD__, ['organization_field_ids']); 41 | } 42 | 43 | $putData = ['organization_field_ids' => $params['organization_field_ids']]; 44 | 45 | $endpoint = $this->getRoute(__FUNCTION__); 46 | $response = $this->client->put($endpoint, $putData); 47 | 48 | return $response; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/OrganizationSubscriptions.php: -------------------------------------------------------------------------------- 1 | getLatestChainedParameter(); 33 | 34 | if (empty($lastChained) || $name !== 'findAll') { 35 | return parent::getRoute($name, $params); 36 | } else { 37 | $id = reset($lastChained); 38 | $chainedResourceNames = array_keys($lastChained); 39 | $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName; 40 | 41 | if ('users' === $chainedResourceName) { 42 | return "users/$id/organization_subscriptions.json"; 43 | } elseif ('organizations' === $chainedResourceName) { 44 | return "organizations/$id/subscriptions.json"; 45 | } else { 46 | return 'organization_subscriptions.json'; 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/OrganizationTickets.php: -------------------------------------------------------------------------------- 1 | setRoutes( 34 | [ 35 | 'findAll' => 'organizations/{organization_id}/tickets.json', 36 | ] 37 | ); 38 | } 39 | 40 | /** 41 | * Returns all tickets for a particular organization 42 | * 43 | * @param array $queryParams 44 | * 45 | * @throws MissingParametersException 46 | * @throws \Exception 47 | * 48 | * @return \stdClass | null 49 | */ 50 | public function findAll(array $queryParams = []) 51 | { 52 | $queryParams = $this->addChainedParametersToParams($queryParams, ['organization_id' => Organizations::class]); 53 | 54 | if (! $this->hasKeys($queryParams, ['organization_id'])) { 55 | throw new MissingParametersException(__METHOD__, ['organization_id']); 56 | } 57 | 58 | return $this->traitFindAll($queryParams); 59 | } 60 | 61 | /* 62 | * Syntactic sugar methods: 63 | * Handy aliases: 64 | */ 65 | 66 | /** 67 | * @param string $id 68 | * @param array $queryQueryParams 69 | * 70 | * @return mixed|void 71 | * @throws CustomException 72 | */ 73 | public function find($id = null, array $queryQueryParams = []) 74 | { 75 | throw new CustomException('Method ' . __METHOD__ 76 | . ' does not exist. Try $client->ticket()->find(ticket_id) instead.'); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/PushNotificationDevices.php: -------------------------------------------------------------------------------- 1 | setRoute('deleteMany', 'push_notification_devices/destroy_many.json'); 22 | } 23 | 24 | /** 25 | * Unregisters the mobile devices that are receiving push notifications. 26 | * Specify the devices as an array of mobile device tokens. 27 | * 28 | * @param array $params 29 | * 30 | * @return null 31 | * @throws MissingParametersException 32 | * @throws \Zendesk\API\Exceptions\RouteException 33 | */ 34 | public function deleteMany(array $params = []) 35 | { 36 | if (! isset($params['tokens']) || ! is_array($params['tokens'])) { 37 | throw new MissingParametersException(__METHOD__, ['tokens']); 38 | } 39 | $postData = [$this->objectNamePlural => $params['tokens']]; 40 | 41 | return $this->client->post($this->getRoute(__FUNCTION__), $postData); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/RequestComments.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 25 | 'find' => 'requests/{requestId}/comments/{id}.json', 26 | 'findAll' => 'requests/{requestId}/comments.json', 27 | ]); 28 | } 29 | 30 | public function findAll(array $params = []) 31 | { 32 | $params = $this->addChainedParametersToParams($params, ['requestId' => Requests::class]); 33 | 34 | return $this->traitFindAll($params); 35 | } 36 | 37 | /** 38 | * Find a specific ticket by id or series of ids 39 | * 40 | * @param $id 41 | * @param array $queryParams 42 | * 43 | * @return \stdClass | null 44 | * @throws MissingParametersException 45 | * @throws \Exception 46 | */ 47 | public function find($id = null, array $queryParams = []) 48 | { 49 | if (empty($id)) { 50 | $id = $this->getChainedParameter(get_class($this)); 51 | } 52 | 53 | if (empty($id)) { 54 | throw new MissingParametersException(__METHOD__, ['id']); 55 | } 56 | 57 | if (! ($requestId = $this->getChainedParameter(Requests::class))) { 58 | throw new MissingParametersException(__METHOD__, ['requestId']); 59 | } 60 | 61 | $route = $this->getRoute(__FUNCTION__, ['id' => $id, 'requestId' => $requestId]); 62 | 63 | return $this->client->get( 64 | $route, 65 | $queryParams 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/SatisfactionRatings.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 31 | 'create' => 'tickets/{ticket_id}/satisfaction_rating.json' 32 | ]); 33 | } 34 | 35 | /** 36 | * Creates a Satisfaction Rating 37 | * https://developer.zendesk.com/rest_api/docs/core/satisfaction_ratings#create-a-satisfaction-rating 38 | * 39 | * @param array $queryParams 40 | * 41 | * @throws MissingParametersException 42 | * @throws \Exception 43 | * 44 | * @return \stdClass | null 45 | */ 46 | public function create(array $queryParams = []) 47 | { 48 | $queryParams = $this->addChainedParametersToParams($queryParams, ['ticket_id' => Tickets::class]); 49 | 50 | if (! $this->hasKeys($queryParams, ['ticket_id'])) { 51 | throw new MissingParametersException(__METHOD__, ['ticket_id']); 52 | } 53 | 54 | return $this->traitCreate($queryParams); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Search.php: -------------------------------------------------------------------------------- 1 | setRoutes( 19 | [ 20 | 'find' => 'search.json', 21 | 'anonymous' => 'portal/search.json' 22 | ] 23 | ); 24 | } 25 | 26 | /** 27 | * 28 | * The search API is a unified search API that returns tickets, users, and organizations. You can define filters to 29 | * narrow your search results according to resource type, dates, and object properties, such as ticket requester or 30 | * tag. 31 | * 32 | * @param string $query 33 | * @param array $queryParams 34 | * 35 | * @return \stdClass | null 36 | * @throws MissingParametersException 37 | * @throws \Zendesk\API\Exceptions\RouteException 38 | */ 39 | public function find($query = null, array $queryParams = []) 40 | { 41 | if (empty($query)) { 42 | throw new MissingParametersException(__METHOD__, ['query']); 43 | } 44 | 45 | $queryParams['query'] = $query; 46 | 47 | return $this->client->get($this->getRoute(__FUNCTION__), $queryParams); 48 | } 49 | 50 | /** 51 | * This resource behaves the same as /api/v2/search, but lets anonymous users search public forums in the Web 52 | * portal. The endpoint searches only articles, not tickets, and returns only articles that 53 | * the requesting user is allowed to see. 54 | * 55 | * @param $query 56 | * @param array $queryParams 57 | * 58 | * @return \stdClass | null 59 | * @throws \Zendesk\API\Exceptions\RouteException 60 | */ 61 | public function anonymous($query, $queryParams = []) 62 | { 63 | $queryParams['query'] = $query; 64 | 65 | return $this->client->get($this->getRoute(__FUNCTION__), $queryParams); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/SharingAgreements.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 31 | 'replace' => "{$this->resourceName}/{id}/replace.json", 32 | 'reorder' => "{$this->resourceName}/reorder.json", 33 | 'definitions' => "{$this->resourceName}/definitions.json", 34 | ]); 35 | } 36 | 37 | /** 38 | * Replace a single SLA Policy 39 | * 40 | * The replaced SLA policy is versioned. Each time an SLA policy is updated, a new SLA policy is saved. 41 | * Altering the title or description of SLA policies doesn't constitute a version change. 42 | * 43 | * @param null $id 44 | * @param array $updateResourceFields 45 | * 46 | * @return \stdClass | null 47 | */ 48 | public function replace($id = null, $updateResourceFields = []) 49 | { 50 | return $this->update($id, $updateResourceFields, __FUNCTION__); 51 | } 52 | 53 | /** 54 | * Reorder SLA Policies 55 | * 56 | * @param array $ids 57 | * 58 | * @return \stdClass | null 59 | */ 60 | public function reorder($ids = []) 61 | { 62 | return $this->client->put($this->getRoute(__FUNCTION__), ['sla_policy_ids' => $ids]); 63 | } 64 | 65 | /** 66 | * Retrieve supported filter definition items 67 | * 68 | * @param array $params 69 | * @return null|\stdClass 70 | * @internal param array $ids 71 | * 72 | */ 73 | public function definitions(array $params = []) 74 | { 75 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/SupportAddresses.php: -------------------------------------------------------------------------------- 1 | setRoute('verify', "{$this->resourceName}/{id}/verify.json"); 21 | } 22 | 23 | /** 24 | * Verify recipient address 25 | * 26 | * @param null $recipientAddressId 27 | * @param array $updateFields 28 | * 29 | * @return \stdClass | null 30 | */ 31 | public function verify($recipientAddressId = null, array $updateFields = []) 32 | { 33 | $class = get_class($this); 34 | if (empty($recipientAddressId)) { 35 | $recipientAddressId = $this->getChainedParameter($class); 36 | } 37 | 38 | return $this->client->put($this->getRoute(__FUNCTION__, ['id' => $recipientAddressId]), $updateFields); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/SuspendedTickets.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 31 | 'recover' => "{$this->resourceName}/{id}/recover.json", 32 | 'recoverMany' => "{$this->resourceName}/recover_many.json", 33 | ]); 34 | } 35 | 36 | /** 37 | * Recovering suspended tickets. 38 | * 39 | * @param $id 40 | * 41 | * @return \stdClass | null 42 | * @throws MissingParametersException 43 | */ 44 | public function recover($id = null) 45 | { 46 | if (empty($id)) { 47 | $id = $this->getChainedParameter(self::class); 48 | } 49 | 50 | if (empty($id)) { 51 | throw new MissingParametersException(__METHOD__, ['id']); 52 | } 53 | 54 | return $this->client->put($this->getRoute(__FUNCTION__, ['id' => $id])); 55 | } 56 | 57 | /** 58 | * Recovering suspended tickets. 59 | * 60 | * @param array $ids 61 | * 62 | * @return \stdClass | null 63 | * @throws MissingParametersException 64 | * @throws \Zendesk\API\Exceptions\ApiResponseException 65 | * @throws \Zendesk\API\Exceptions\RouteException 66 | * 67 | */ 68 | public function recoverMany(array $ids) 69 | { 70 | if (! is_array($ids)) { 71 | throw new MissingParametersException(__METHOD__, ['ids']); 72 | } 73 | 74 | $response = Http::send( 75 | $this->client, 76 | $this->getRoute(__FUNCTION__), 77 | [ 78 | 'method' => 'PUT', 79 | 'queryParams' => ['ids' => implode(',', $ids)], 80 | ] 81 | ); 82 | 83 | return $response; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Tags.php: -------------------------------------------------------------------------------- 1 | getLatestChainedParameter(); 51 | 52 | if (empty($lastChained)) { 53 | throw new CustomException('The ' . $name . '() method needs to be called while chaining.'); 54 | } 55 | 56 | $id = reset($lastChained); 57 | $chainedResourceNames = array_keys($lastChained); 58 | $resource = (new $chainedResourceNames[0]($this->client))->resourceName; 59 | 60 | return "$resource/$id/tags.json"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Targets.php: -------------------------------------------------------------------------------- 1 | TicketFieldsOptions::class, 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/TicketForms.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 31 | 'clone' => 'ticket_forms/{id}/clone.json', 32 | 'reorder' => 'ticket_forms/reorder.json' 33 | ]); 34 | } 35 | 36 | /** 37 | * Clones an existing ticket form (can't use 'clone' as method name) 38 | * 39 | * @param int $id 40 | * @return null|\stdClass 41 | * @throws MissingParametersException 42 | * @internal param array $params 43 | * 44 | */ 45 | public function cloneForm($id = null) 46 | { 47 | $class = get_class($this); 48 | if (empty($id)) { 49 | $id = $this->getChainedParameter($class); 50 | } 51 | 52 | if (empty($id)) { 53 | throw new MissingParametersException(__METHOD__, ['id']); 54 | } 55 | 56 | return $this->client->post($this->getRoute('clone', ['id' => $id])); 57 | } 58 | 59 | /** 60 | * Reorder Ticket forms 61 | * 62 | * @param array $ticketFormIds 63 | * 64 | * @throws ResponseException 65 | * @throws \Exception 66 | * @return \stdClass | null 67 | */ 68 | public function reorder(array $ticketFormIds) 69 | { 70 | $response = Http::send( 71 | $this->client, 72 | $this->getRoute(__FUNCTION__), 73 | ['postFields' => ['ticket_form_ids' => $ticketFormIds], 'method' => 'PUT'] 74 | ); 75 | 76 | return $response; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/TicketImports.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 30 | 'create' => 'imports/tickets.json', 31 | 'createMany' => 'imports/tickets/create_many.json', 32 | ]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/TicketMetrics.php: -------------------------------------------------------------------------------- 1 | setRoute('findAll', "{$this->resourceName}.json"); 25 | $this->setRoute('find', "{$this->resourceName}/{id}.json"); 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function getRoute($name, array $params = []) 32 | { 33 | if ('find' === $name || 'findAll' === $name) { 34 | $lastChained = $this->getChainedParameter(Tickets::class); 35 | 36 | if (! empty($lastChained)) { 37 | return "tickets/$lastChained/metrics.json"; 38 | } 39 | } 40 | 41 | return parent::getRoute($name, $params); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Translations.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 22 | 'manifest' => "{$this->resourceName}/manifest.json", 23 | ]); 24 | } 25 | 26 | /** 27 | * Get the manifest json file 28 | * 29 | * @param array $params 30 | * 31 | * @throws \Exception 32 | * 33 | * @return \stdClass | null 34 | */ 35 | public function manifest(array $params = []) 36 | { 37 | return $this->findAll($params, __FUNCTION__); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Triggers.php: -------------------------------------------------------------------------------- 1 | setRoute('findActive', "{$this->resourceName}/active.json"); 21 | } 22 | 23 | /** 24 | * Finds all active triggers 25 | * 26 | * @param array $params 27 | * 28 | * @return \stdClass | null 29 | * @throws \Zendesk\API\Exceptions\RouteException 30 | */ 31 | public function findActive($params = []) 32 | { 33 | return $this->client->get($this->getRoute(__FUNCTION__), $params); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/TwitterHandles.php: -------------------------------------------------------------------------------- 1 | setRoute('reorder', "{$this->resourceName}/reorder.json"); 22 | } 23 | 24 | /** 25 | * Reorder user fields 26 | * 27 | * @param array $params 28 | * 29 | * @return \stdClass | null 30 | */ 31 | public function reorder(array $params) 32 | { 33 | $postFields = ['user_field_ids' => $params]; 34 | 35 | $response = Http::send( 36 | $this->client, 37 | $this->getRoute(__FUNCTION__), 38 | ['postFields' => $postFields, 'method' => 'PUT'] 39 | ); 40 | 41 | return $response; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Core/Webhooks.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 25 | 'create' => "{$this->resourceName}", 26 | 'update' => "{$this->resourceName}/{id}", 27 | 'delete' => "{$this->resourceName}/{id}", 28 | 'findAll' => "{$this->resourceName}", 29 | ]); 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function findAll(array $params = []) 36 | { 37 | $queryParams = array_filter(array_flip($params), [$this, 'filterParams']); 38 | $queryParams = array_merge($params, array_flip($queryParams)); 39 | 40 | return $this->traitFindAll($queryParams); 41 | } 42 | 43 | /** 44 | * Filter parameters passed and only allow valid query parameters. 45 | * 46 | * @param $param 47 | * @return int 48 | */ 49 | private function filterParams($param) 50 | { 51 | return preg_match("/^sort|page[[a-zA-Z_]*]|filter[[a-zA-Z_]*](\\[\\]?)/", $param); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Embeddable.php: -------------------------------------------------------------------------------- 1 | client->embeddable 12 | * 13 | * @method ConfigSets configSets() 14 | */ 15 | class Embeddable 16 | { 17 | use ChainedParametersTrait; 18 | use InstantiatorTrait; 19 | 20 | public $client; 21 | 22 | /** 23 | * Sets the client to be used 24 | * 25 | * @param HttpClient $client 26 | */ 27 | public function __construct(HttpClient $client) 28 | { 29 | $this->client = $client; 30 | } 31 | 32 | /** 33 | * @inheritdoc 34 | * @return array 35 | */ 36 | public static function getValidSubResources() 37 | { 38 | return [ 39 | 'configSets' => ConfigSets::class, 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Embeddable/ConfigSets.php: -------------------------------------------------------------------------------- 1 | client->helpCenter 14 | * 15 | * @method Categories categories() 16 | * @method Sections sections() 17 | * @method Articles articles() 18 | */ 19 | class HelpCenter 20 | { 21 | use ChainedParametersTrait; 22 | use InstantiatorTrait; 23 | 24 | public $client; 25 | 26 | /** 27 | * Sets the client to be used 28 | * 29 | * @param HttpClient $client 30 | */ 31 | public function __construct(HttpClient $client) 32 | { 33 | $this->client = $client; 34 | } 35 | 36 | /** 37 | * @inheritdoc 38 | * @return array 39 | */ 40 | public static function getValidSubResources() 41 | { 42 | return [ 43 | 'categories' => Categories::class, 44 | 'sections' => Sections::class, 45 | 'articles' => Articles::class, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/HelpCenter/Categories.php: -------------------------------------------------------------------------------- 1 | Sections::class, 36 | ]; 37 | } 38 | 39 | /** 40 | * @inheritdoc 41 | */ 42 | protected function setUpRoutes() 43 | { 44 | $this->setRoute('updateSourceLocale', "{$this->resourceName}/{categoryId}/source_locale.json"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/HelpCenter/ResourceAbstract.php: -------------------------------------------------------------------------------- 1 | client->sell 12 | * 13 | * @method Contacts contacts() 14 | */ 15 | class Sell 16 | { 17 | use ChainedParametersTrait; 18 | use InstantiatorTrait; 19 | 20 | public $client; 21 | 22 | /** 23 | * Sets the client to be used 24 | * 25 | * @param HttpClient $client 26 | */ 27 | public function __construct(HttpClient $client) 28 | { 29 | $this->client = $client; 30 | } 31 | 32 | /** 33 | * @inheritdoc 34 | * @return array 35 | */ 36 | public static function getValidSubResources() 37 | { 38 | return [ 39 | 'contacts' => Contacts::class, 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Sell/Contacts.php: -------------------------------------------------------------------------------- 1 | setRoutes([ 41 | "find" => "{$this->resourceName}/{id}", 42 | "findAll" => $this->resourceName, 43 | "create" => $this->resourceName, 44 | "update" => "{$this->resourceName}/{id}", 45 | "delete" => "{$this->resourceName}/{id}", 46 | "upsert" => "{$this->resourceName}/upsert", 47 | ]); 48 | } 49 | 50 | /** 51 | * Create a new contact or update an existing, based on a value of a filter or a set of filters 52 | * @param array $params 53 | * @param array $updateResourceFields 54 | * @return \stdClass|null 55 | * @throws \Zendesk\API\Exceptions\ApiResponseException 56 | * @throws \Zendesk\API\Exceptions\AuthException 57 | */ 58 | public function upsert(array $params, array $updateResourceFields) 59 | { 60 | $route = $this->getRoute(__FUNCTION__); 61 | 62 | return $this->client->post( 63 | $route, 64 | [$this->objectName => $updateResourceFields], 65 | ['queryParams' => $params] 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Sell/ResourceAbstract.php: -------------------------------------------------------------------------------- 1 | client->talk 13 | * 14 | * @method Stats stats() 15 | */ 16 | class Talk 17 | { 18 | use ChainedParametersTrait; 19 | use InstantiatorTrait; 20 | 21 | public $client; 22 | 23 | /** 24 | * Sets the client to be used 25 | * 26 | * @param HttpClient $client 27 | */ 28 | public function __construct(HttpClient $client) 29 | { 30 | $this->client = $client; 31 | } 32 | 33 | /** 34 | * @inheritdoc 35 | * @return array 36 | */ 37 | public static function getValidSubResources() 38 | { 39 | return [ 40 | 'stats' => Stats::class, 41 | ]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Talk/ResourceAbstract.php: -------------------------------------------------------------------------------- 1 | client->helpCenter 12 | * 13 | * @method PhoneNumbers phoneNumbers() 14 | */ 15 | class Voice 16 | { 17 | use ChainedParametersTrait; 18 | use InstantiatorTrait; 19 | 20 | public $client; 21 | 22 | /** 23 | * Sets the client to be used 24 | * 25 | * @param HttpClient $client 26 | */ 27 | public function __construct(HttpClient $client) 28 | { 29 | $this->client = $client; 30 | } 31 | 32 | /** 33 | * @inheritdoc 34 | * @return array 35 | */ 36 | public static function getValidSubResources() 37 | { 38 | return [ 39 | 'phoneNumbers' => PhoneNumbers::class, 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Voice/PhoneNumbers.php: -------------------------------------------------------------------------------- 1 | setRoute('search', "{$this->getResourceName()}/search.json"); 21 | } 22 | 23 | /** 24 | * Search for available phone numbers. 25 | * 26 | * @param array $queryParams 27 | * 28 | * @return \stdClass 29 | * @throws \Zendesk\API\Exceptions\RouteException 30 | */ 31 | public function search(array $queryParams = []) 32 | { 33 | return $this->client->get($this->getRoute(__FUNCTION__), $queryParams); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Zendesk/API/Resources/Voice/ResourceAbstract.php: -------------------------------------------------------------------------------- 1 | getRoute($routeKey, $params); 21 | } catch (RouteException $e) { 22 | if (!isset($this->resourceName)) { 23 | $this->resourceName = $this->getResourceNameFromClass(); 24 | } 25 | 26 | $route = $this->resourceName . '.json'; 27 | $this->setRoute(__FUNCTION__, $route); 28 | } 29 | 30 | return $this->client->post( 31 | $route, 32 | [$this->objectName => $params] 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/CreateMany.php: -------------------------------------------------------------------------------- 1 | getRoute(__FUNCTION__); 28 | } catch (RouteException $e) { 29 | if (! isset($this->resourceName)) { 30 | $this->resourceName = $this->getResourceNameFromClass(); 31 | } 32 | 33 | $route = $this->resourceName . '/create_many.json'; 34 | $this->setRoute('createMany', $route); 35 | } 36 | 37 | return $this->client->post($route, [$this->objectNamePlural => $params]); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/CreateOrUpdateMany.php: -------------------------------------------------------------------------------- 1 | getRoute(__FUNCTION__); 23 | } catch (RouteException $e) { 24 | if (! isset($this->resourceName)) { 25 | $this->resourceName = $this->getResourceNameFromClass(); 26 | } 27 | 28 | $route = $this->resourceName . '/create_or_update_many.json'; 29 | $this->setRoute('createOrUpdateMany', $route); 30 | } 31 | 32 | 33 | $response = $this->client->post( 34 | $route, 35 | [$this->objectNamePlural => $params] 36 | ); 37 | 38 | return $response; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/Defaults.php: -------------------------------------------------------------------------------- 1 | getChainedParameters(); 22 | if (array_key_exists(get_class($this), $chainedParameters)) { 23 | $id = $chainedParameters[get_class($this)]; 24 | } 25 | } 26 | 27 | if (empty($id)) { 28 | throw new MissingParametersException(__METHOD__, ['id']); 29 | } 30 | 31 | try { 32 | $route = $this->getRoute($routeKey, ['id' => $id]); 33 | } catch (RouteException $e) { 34 | if (! isset($this->resourceName)) { 35 | $this->resourceName = $this->getResourceNameFromClass(); 36 | } 37 | 38 | $this->setRoute(__FUNCTION__, $this->resourceName . '/{id}.json'); 39 | $route = $this->resourceName . '/' . $id . '.json'; 40 | } 41 | 42 | return $this->client->delete($route); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/DeleteMany.php: -------------------------------------------------------------------------------- 1 | getRoute(__FUNCTION__); 27 | } catch (RouteException $e) { 28 | if (! isset($this->resourceName)) { 29 | $this->resourceName = $this->getResourceNameFromClass(); 30 | } 31 | 32 | $route = $this->resourceName . '/destroy_many.json'; 33 | $this->setRoute('', $route); 34 | } 35 | 36 | $response = Http::send( 37 | $this->client, 38 | $route, 39 | [ 40 | 'method' => 'DELETE', 41 | 'queryParams' => [$key => implode(',', $ids)] 42 | ] 43 | ); 44 | 45 | $this->client->setSideload(null); 46 | 47 | return $response; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/Find.php: -------------------------------------------------------------------------------- 1 | getChainedParameter(get_class($this)); 24 | } 25 | 26 | if (empty($id)) { 27 | throw new MissingParametersException(__METHOD__, ['id']); 28 | } 29 | 30 | try { 31 | $route = $this->getRoute($routeKey, ['id' => $id]); 32 | } catch (RouteException $e) { 33 | if (! isset($this->resourceName)) { 34 | $this->resourceName = $this->getResourceNameFromClass(); 35 | } 36 | 37 | $this->setRoute(__FUNCTION__, $this->resourceName . '/{id}.json'); 38 | $route = $this->resourceName . '/' . $id . '.json'; 39 | } 40 | 41 | return $this->client->get( 42 | $route, 43 | $queryParams 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/FindAll.php: -------------------------------------------------------------------------------- 1 | getRoute($routeKey, $params); 26 | } catch (RouteException $e) { 27 | if (!isset($this->resourceName)) { 28 | $this->resourceName = $this->getResourceNameFromClass(); 29 | } 30 | 31 | $route = $this->resourceName . '.json'; 32 | $this->setRoute(__FUNCTION__, $route); 33 | } 34 | 35 | return $this->client->get( 36 | $route, 37 | $params 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/FindMany.php: -------------------------------------------------------------------------------- 1 | getRoute(__FUNCTION__); 27 | } catch (RouteException $e) { 28 | if (! isset($this->resourceName)) { 29 | $this->resourceName = $this->getResourceNameFromClass(); 30 | } 31 | 32 | $route = $this->resourceName . '/show_many.json'; 33 | $this->setRoute('findMany', $route); 34 | } 35 | 36 | $queryParams = []; 37 | 38 | if (count($ids) > 0) { 39 | $queryParams[$key] = implode(',', $ids); 40 | } 41 | 42 | return $this->client->get($route, array_merge($queryParams, $extraParams)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/Locales.php: -------------------------------------------------------------------------------- 1 | locale; 22 | } 23 | 24 | /** 25 | * @param string $locale 26 | * @return Locales 27 | */ 28 | public function setLocale($locale) 29 | { 30 | if (is_string($locale)) { 31 | $this->locale = $locale; 32 | } 33 | 34 | return $this; 35 | } 36 | 37 | /** 38 | * Generate a route depending on a localization set 39 | * @param string $name 40 | * @param array $params 41 | */ 42 | public function getRoute($name, array $params = []) 43 | { 44 | $routesWithLocale = ['findAll', 'find', 'create', 'update']; 45 | 46 | $locale = $this->getLocale(); 47 | $resourceName = parent::getResourceNameFromClass(); 48 | 49 | if (in_array($name, $routesWithLocale) && isset($locale)) { 50 | $originalResourceName = $this->resourceName; 51 | $temp = explode('/', $resourceName); 52 | $className = $temp[count($temp) - 1]; 53 | $this->resourceName = "help_center/$locale/" . $className; 54 | 55 | $route = parent::getRoute($name, $params); 56 | 57 | // Reset resourceName so it doesn't affect succeeding calls 58 | $this->resourceName = $originalResourceName; 59 | 60 | return $route; 61 | } else { 62 | return parent::getRoute($name, $params); 63 | } 64 | } 65 | 66 | /** 67 | * Updates a resource's source_locale property 68 | * 69 | * @param int $categoryId The category to update 70 | * @param string $sourceLocale The new source_locale 71 | * 72 | * @return array 73 | * @throws \Zendesk\API\Exceptions\RouteException 74 | */ 75 | public function updateSourceLocale($categoryId, $sourceLocale) 76 | { 77 | if (empty($categoryId)) { 78 | $categoryId = $this->getChainedParameter(get_class($this)); 79 | } 80 | 81 | return $this->client->put( 82 | $this->getRoute(__FUNCTION__, ["{$this->objectName}Id" => $categoryId]), 83 | ["{$this->objectName}_locale" => $sourceLocale] 84 | ); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/Pagination.php: -------------------------------------------------------------------------------- 1 | tickets()->iterator(); 13 | * foreach ($ticketsIterator as $ticket) { 14 | * process($ticket); 15 | * } 16 | * 17 | * @return PaginationIterator to fetch all pages. 18 | */ 19 | public function iterator($params = [], $method = 'findAll') 20 | { 21 | $strategyClass = $this->paginationStrategyClass(); 22 | $strategy = new $strategyClass($this->resourcesKey(), $params); 23 | 24 | return new PaginationIterator($this, $strategy, $method); 25 | } 26 | 27 | /** 28 | * Override this method in your resources 29 | * 30 | * @return string subclass of AbstractStrategy used for fetching pages 31 | */ 32 | protected function paginationStrategyClass() 33 | { 34 | return CbpStrategy::class; 35 | } 36 | 37 | /** 38 | * The key in the API responses where the resources are returned 39 | * 40 | * @return string eg: "job_statuses" 41 | */ 42 | protected function resourcesKey() 43 | { 44 | return $this->objectNamePlural; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/ResourceName.php: -------------------------------------------------------------------------------- 1 | prefix . $resourceName; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/Search.php: -------------------------------------------------------------------------------- 1 | getRoute(__FUNCTION__, $params); 19 | } catch (RouteException $e) { 20 | if (! isset($this->resourceName)) { 21 | $this->resourceName = $this->getResourceNameFromClass(); 22 | } 23 | 24 | $route = $this->resourceName . '/search.json'; 25 | $this->setRoute(__FUNCTION__, $route); 26 | } 27 | 28 | return $this->client->get($route, $params); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/Update.php: -------------------------------------------------------------------------------- 1 | getChainedParameter($class); 23 | } 24 | 25 | try { 26 | $route = $this->getRoute($routeKey, ['id' => $id]); 27 | } catch (RouteException $e) { 28 | if (! isset($this->resourceName)) { 29 | $this->resourceName = $this->getResourceNameFromClass(); 30 | } 31 | 32 | $this->setRoute(__FUNCTION__, $this->resourceName . '/{id}.json'); 33 | $route = $this->resourceName . '/' . $id . '.json'; 34 | } 35 | 36 | return $this->client->put( 37 | $route, 38 | [$this->objectName => $updateResourceFields] 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Resource/UpdateMany.php: -------------------------------------------------------------------------------- 1 | getRoute(__FUNCTION__); 25 | } catch (RouteException $e) { 26 | if (! isset($this->resourceName)) { 27 | $this->resourceName = $this->getResourceNameFromClass(); 28 | } 29 | 30 | $route = $this->resourceName . '/update_many.json'; 31 | $this->setRoute('updateMany', $route); 32 | } 33 | 34 | $resourceUpdateName = $this->objectNamePlural; 35 | $queryParams = []; 36 | if (isset($params[$key]) && is_array($params[$key])) { 37 | $queryParams[$key] = implode(',', $params[$key]); 38 | unset($params[$key]); 39 | 40 | $resourceUpdateName = $this->objectName; 41 | } 42 | 43 | $response = Http::send( 44 | $this->client, 45 | $route, 46 | [ 47 | 'queryParams' => $queryParams, 48 | 'postFields' => [$resourceUpdateName => $params], 49 | 'method' => 'PUT' 50 | ] 51 | ); 52 | 53 | $this->client->setSideload(null); 54 | 55 | return $response; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Utility/InstantiatorTrait.php: -------------------------------------------------------------------------------- 1 | tickets can be referenced by $client->tickets() 19 | * 20 | * @param $name 21 | * @param $arguments 22 | * 23 | * @return ChainedParametersTrait 24 | * @throws \Exception 25 | */ 26 | public function __call($name, $arguments) 27 | { 28 | if ((array_key_exists($name, $validSubResources = $this::getValidSubResources()))) { 29 | $className = $validSubResources[$name]; 30 | $client = ($this instanceof HttpClient) ? $this : $this->client; 31 | $class = new $className($client); 32 | } else { 33 | throw new \Exception("No method called $name available in " . __CLASS__); 34 | } 35 | 36 | $chainedParams = ($this instanceof ResourceAbstract) ? $this->getChainedParameters() : []; 37 | 38 | if ((isset($arguments[0])) && ($arguments[0] != null)) { 39 | $chainedParams = array_merge($chainedParams, [get_class($class) => $arguments[0]]); 40 | } 41 | 42 | $class = $class->setChainedParameters($chainedParams); 43 | 44 | return $class; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Utility/Pagination/AbstractStrategy.php: -------------------------------------------------------------------------------- 1 | resourcesKey = $resourcesKey; 18 | $this->params = $params; 19 | } 20 | 21 | public function params() 22 | { 23 | return $this->params; 24 | } 25 | 26 | /** 27 | * Returns the latest HTTP response, unless an error occurred, which causes an exception 28 | * 29 | * @return \GuzzleHttp\Psr7\Response 30 | */ 31 | public function latestResponse() 32 | { 33 | return $this->latestResponse; 34 | } 35 | 36 | /** 37 | * From the params or the default value 38 | * 39 | * @return integer 40 | */ 41 | protected function pageSize() 42 | { 43 | if (isset($this->pageSize)) { 44 | return $this->pageSize; 45 | } elseif (isset($this->params['page[size]'])) { 46 | $this->pageSize = $this->params['page[size]']; 47 | } elseif (isset($this->params['per_page'])) { 48 | $this->pageSize = $this->params['per_page']; 49 | } else { 50 | $this->pageSize = DEFAULT_PAGE_SIZE; 51 | } 52 | 53 | return $this->pageSize; 54 | } 55 | 56 | abstract public function page($getPageFn); 57 | abstract public function shouldGetPage($current_page); 58 | } 59 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php: -------------------------------------------------------------------------------- 1 | started = true; 18 | $this->latestResponse = $getPageFn(); 19 | if (!isset($this->latestResponse->meta->has_more)) { 20 | throw new PaginationError( 21 | "Response not conforming to the CBP format, if you think your request is correct, please open an issue at https://github.com/zendesk/zendesk_api_client_php/issues" 22 | ); 23 | } 24 | $this->hasMore = $this->latestResponse->meta->has_more; 25 | if (isset($this->latestResponse->meta->after_cursor)) { 26 | $this->afterCursor = $this->latestResponse->meta->after_cursor; 27 | } 28 | 29 | return $this->latestResponse->{$this->resourcesKey}; 30 | } 31 | 32 | public function shouldGetPage($current_page) 33 | { 34 | return !$this->started || $this->hasMore; 35 | } 36 | 37 | public function params() 38 | { 39 | $result = array_merge($this->params, $this->paginationParams()); 40 | $result = $this->unsetObpParams($result); 41 | 42 | return $result; 43 | } 44 | 45 | /** 46 | * The params that are needed to for pagination (eg: ["page[size]" => "100"]) 47 | * If OBP params are passed, they are converted to CBP 48 | * 49 | * @return array Params for pagination 50 | */ 51 | private function paginationParams() 52 | { 53 | $result = isset($this->afterCursor) ? ['page[after]' => $this->afterCursor] : []; 54 | 55 | return array_merge(['page[size]' => $this->pageSize()], $result); 56 | } 57 | 58 | private function unsetObpParams($params) 59 | { 60 | unset( 61 | $params['page'], 62 | $params['per_page'], 63 | $params['sort_by'], 64 | $params['sort_order'] 65 | ); 66 | return $params; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php: -------------------------------------------------------------------------------- 1 | pageNumber; 16 | $response = $getPageFn(); 17 | 18 | return $response->{$this->resourcesKey}; 19 | } 20 | 21 | public function shouldGetPage($current_page) 22 | { 23 | return $this->pageNumber == 0 || count($current_page) == 0; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Utility/Pagination/PaginationError.php: -------------------------------------------------------------------------------- 1 | tickets()` which uses FindAll 19 | * @param AbstractStrategy $strategy For pagination Logic (OBP, CBP, SinglePage) 20 | * @param string $method used to make the API call 21 | */ 22 | public function __construct($clientList, AbstractStrategy $strategy, $method) 23 | { 24 | $this->clientList = $clientList; 25 | $this->strategy = $strategy; 26 | $this->method = $method; 27 | } 28 | 29 | #[\ReturnTypeWillChange] 30 | public function key() 31 | { 32 | return $this->position; 33 | } 34 | 35 | #[\ReturnTypeWillChange] 36 | public function next() 37 | { 38 | ++$this->position; 39 | } 40 | 41 | #[\ReturnTypeWillChange] 42 | public function rewind() 43 | { 44 | $this->position = 0; 45 | } 46 | 47 | #[\ReturnTypeWillChange] 48 | public function valid() 49 | { 50 | $this->getPageIfNeeded(); 51 | return !!$this->current(); 52 | } 53 | 54 | #[\ReturnTypeWillChange] 55 | public function current() 56 | { 57 | if (isset($this->page[$this->position])) { 58 | return $this->page[$this->position]; 59 | } else { 60 | return null; 61 | } 62 | } 63 | 64 | /** 65 | * Returns the latest HTTP response, unless an error occurred, which causes an exception 66 | * 67 | * @return \GuzzleHttp\Psr7\Response 68 | */ 69 | public function latestResponse() 70 | { 71 | return $this->strategy->latestResponse(); 72 | } 73 | private function getPageIfNeeded() 74 | { 75 | if (isset($this->page[$this->position]) || !$this->strategy->shouldGetPage($this->page)) { 76 | return; 77 | } 78 | 79 | $getPageFn = function () { 80 | return $this->clientList->{$this->method}($this->strategy->params()); 81 | }; 82 | $this->page = $this->strategy->page($getPageFn); 83 | $this->position = 0; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Zendesk/API/Traits/Utility/Pagination/SinglePageStrategy.php: -------------------------------------------------------------------------------- 1 | started = true; 16 | $response = $getPageFn(); 17 | 18 | return $response->{$this->resourcesKey}; 19 | } 20 | 21 | public function shouldGetPage($current_page) 22 | { 23 | return !$this->started; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Zendesk/Console/ConsoleCommand.php: -------------------------------------------------------------------------------- 1 | setName('console') 25 | ->setDescription('Test out features of the php api client.') 26 | ->addArgument('subdomain', InputArgument::OPTIONAL) 27 | ->addArgument('username', InputArgument::OPTIONAL) 28 | ->addArgument('token', InputArgument::OPTIONAL); 29 | } 30 | 31 | /** 32 | * Execute the command. 33 | * 34 | * @param \Symfony\Component\Console\Input\InputInterface $input 35 | * @param \Symfony\Component\Console\Output\OutputInterface $output 36 | * 37 | * @throws RuntimeException 38 | * 39 | * @return void 40 | */ 41 | protected function execute(InputInterface $input, OutputInterface $output) 42 | { 43 | $config = new Configuration(); 44 | 45 | $client = new HttpClient($input->getArgument('subdomain')); 46 | $client->setAuth('basic', [ 47 | 'username' => $input->getArgument('username'), 48 | 'token' => $input->getArgument('token') 49 | ]); 50 | 51 | try { 52 | $data = $client->users()->me(); 53 | $config->setStartupMessage( 54 | 'Hi ' . 55 | $data->user->name . 56 | '. An instance of HttpClient using your credentials is stored on $client variable.' 57 | ); 58 | } catch (ApiResponseException $e) { 59 | $config->setStartupMessage('Invalid client credentials'); 60 | } 61 | 62 | $shell = new Shell($config); 63 | $shell->setScopeVariables(compact('client')); 64 | $shell->run(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Zendesk/Console/Shell.php: -------------------------------------------------------------------------------- 1 | resourceName = $resourceName; 24 | $this->resources = $resources; 25 | $this->callCount = 0; 26 | } 27 | 28 | public function findAll($params) 29 | { 30 | if ($this->errorMessage) { 31 | $request = new Request('GET', 'http://example.zendesk.com'); 32 | $this->response = new Response(400, [], '{ "a": "json"}'); 33 | $requestException = new RequestException($this->errorMessage, $request, $this->response); 34 | throw new ApiResponseException($requestException); 35 | } elseif ($this->isObp) { 36 | $this->response = (object) [ 37 | $this->resourceName => $this->resources[0], 38 | // No CBP meta and links 39 | ]; 40 | } else { 41 | // Simulate two pages of resources 42 | $resources = $this->callCount === 0 43 | ? $this->resources[0] 44 | : $this->resources[1]; 45 | 46 | // Simulate a cursor for the next page on the first call 47 | $afterCursor = $this->callCount === 0 ? 'cursor_for_next_page' : null; 48 | 49 | $this->callCount++; 50 | $this->params = $params; 51 | $this->response = (object) [ 52 | $this->resourceName => $resources, 53 | 'meta' => (object) [ 54 | 'has_more' => $afterCursor !== null, 55 | 'after_cursor' => $afterCursor, 56 | ], 57 | ]; 58 | } 59 | 60 | return $this->response; 61 | } 62 | 63 | public function findDifferent($params) 64 | { 65 | $this->foundDifferent = true; 66 | return $this->findAll($params); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Zendesk/API/LiveTests/AuthTest.php: -------------------------------------------------------------------------------- 1 | client->setAuth('basic', ['username' => $this->username, 'token' => $this->token]); 16 | $users = $this->client->users()->findAll(); 17 | $this->assertTrue(isset($users->users), 'Should return a valid user object.'); 18 | } 19 | 20 | /** 21 | * Test the use of basic test 22 | */ 23 | public function testOAuth() 24 | { 25 | $this->client->setAuth('oauth', ['token' => $this->oAuthToken]); 26 | $users = $this->client->users()->findAll(); 27 | $this->assertTrue(isset($users->users), 'Should return a valid user object.'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Zendesk/API/LiveTests/BasicTest.php: -------------------------------------------------------------------------------- 1 | subdomain = getenv('SUBDOMAIN'); 57 | $this->username = getenv('USERNAME'); 58 | $this->password = getenv('PASSWORD'); 59 | $this->token = getenv('TOKEN'); 60 | $this->oAuthToken = getenv('OAUTH_TOKEN'); 61 | $this->scheme = getenv('SCHEME'); 62 | $this->hostname = getenv('HOSTNAME'); 63 | $this->port = getenv('PORT'); 64 | $this->authStrategy = getenv('AUTH_STRATEGY'); 65 | 66 | parent::__construct($name, $data, $dataName); 67 | } 68 | 69 | /** 70 | * Sets up the fixture, for example, open a network connection. 71 | * This method is called before a test is executed. 72 | */ 73 | protected function setUp(): void 74 | { 75 | $this->client = new HttpClient($this->subdomain, $this->username, $this->scheme, $this->hostname, $this->port); 76 | 77 | $authOptions['username'] = $this->username; 78 | if ($this->authStrategy === 'basic') { 79 | $authOptions['token'] = $this->token; 80 | } else { 81 | $authOptions['token'] = $this->oAuthToken; 82 | } 83 | 84 | $this->client->setAuth($this->authStrategy, $authOptions); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/Zendesk/API/LiveTests/HelpCenterTest.php: -------------------------------------------------------------------------------- 1 | client->helpCenter->articles()->iterator(); 13 | 14 | $actual = iterator_to_array($iterator); 15 | 16 | // Generally, there should be at least one article in the help center, even if these are just the default articles. 17 | $this->assertTrue(is_array($actual) && count($actual) > 0, 'Should return a non-empty array of articles.'); 18 | } 19 | 20 | public function testIterateOverHelpCenterSections() 21 | { 22 | $iterator = $this->client->helpCenter->sections()->iterator(); 23 | 24 | $actual = iterator_to_array($iterator); 25 | 26 | // Generally, there should be at least one section in the help center, even if these are just the default sections. 27 | $this->assertTrue(is_array($actual) && count($actual) > 0, 'Should return a non-empty array of sections.'); 28 | } 29 | 30 | public function testIterateOverHelpCenterCategories() 31 | { 32 | $iterator = $this->client->helpCenter->categories()->iterator(); 33 | 34 | $actual = iterator_to_array($iterator); 35 | 36 | // Generally, there should be at least one category in the help center, even if these are just the default categories. 37 | $this->assertTrue(is_array($actual) && count($actual) > 0, 'Should return a non-empty array of categories.'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/Zendesk/API/LiveTests/SearchTest.php: -------------------------------------------------------------------------------- 1 | client->search()->find('type:ticket status:open', ['sort_by' => 'updated_at']); 13 | 14 | $this->assertTrue(isset($response->results), 'Should contain a property called `results`'); 15 | $this->assertTrue( 16 | is_array($response->results) && count($response->results) > 0, 17 | 'Should contain a non-empty `results` array.' 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Chat/AppsTest.php: -------------------------------------------------------------------------------- 1 | $faker->numberBetween(1), 18 | 'product_name' => 'chat', 19 | 'settings' => 20 | [ 21 | 'name' => $faker->word, 22 | 'api_token' => $faker->md5, 23 | ], 24 | ]; 25 | 26 | $this->assertEndpointCalled(function () use ($postFields) { 27 | $this->client->chat->apps()->install($postFields); 28 | }, 'apps/installations.json', 'POST', [ 29 | 'postFields' => $postFields, 30 | 'apiBasePath' => '/api/v2/' 31 | ]); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Chat/IntegrationsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 15 | $this->client->chat->integrations()->find(); 16 | }, 'zopim_integration.json', 'GET'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->apps()->installationLocations(), 'find')); 18 | $this->assertTrue(method_exists($this->client->apps()->installationLocations(), 'findAll')); 19 | } 20 | 21 | /** 22 | * Test the reorder method 23 | * 24 | */ 25 | public function testReorder() 26 | { 27 | $postFields = [ 28 | 'installations' => [82, 56], 29 | 'location_name' => 'nav_bar' 30 | ]; 31 | 32 | $this->assertEndpointCalled(function () use ($postFields) { 33 | $this->client->apps()->installationLocations()->reorder($postFields); 34 | }, 'apps/location_installations/reorder.json', 'POST', ['postFields' => $postFields]); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/AppLocationsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->apps()->locations(), 'find')); 19 | $this->assertTrue(method_exists($this->client->apps()->locations(), 'findAll')); 20 | } 21 | 22 | /** 23 | * Test if the methods can be called via apps() 24 | */ 25 | public function testMethodsCallable() 26 | { 27 | $this->assertEndpointCalled(function () { 28 | $this->client->apps()->locations()->findAll(['per_page' => 20]); 29 | }, 'apps/locations.json', 'GET', ['queryParams' => ['per_page' => 20]]); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/AuditLogsTest.php: -------------------------------------------------------------------------------- 1 | 'actor_id', 19 | 'sort_order' => 'desc', 20 | 'filter[source_type]' => 'rule', 21 | 'filter[valid]' => 'somerule', 22 | 'filter[created_at][]' => '2016-01-01T00:00:00Z' 23 | ]; 24 | 25 | // We expect invalid parameters are removed. 26 | // We also expect url encoded keys and values 27 | $expectedQueryParams = []; 28 | foreach ($queryParams as $key => $value) { 29 | $expectedQueryParams = array_merge($expectedQueryParams, [urlencode($key) => $value]); 30 | } 31 | 32 | $this->assertEndpointCalled( 33 | function () use ($queryParams) { 34 | $this->client->auditLogs()->findAll($queryParams); 35 | }, 36 | 'audit_logs.json', 37 | 'GET', 38 | ['queryParams' => $expectedQueryParams] 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/AuthTest.php: -------------------------------------------------------------------------------- 1 | client->setAuth('basic', ['username' => $this->username, 'token' => $this->token]); 20 | 21 | $currentRequest = new Request('GET', 'http://www.endpoint.com/test.json'); 22 | $currentRequestOptions = ['existing' => 'option']; 23 | 24 | list ($request, $requestOptions) = $this->client->getAuth()->prepareRequest( 25 | $currentRequest, 26 | $currentRequestOptions 27 | ); 28 | 29 | $this->assertInstanceOf(Request::class, $request, 'Should have returned a request'); 30 | 31 | $this->assertArrayHasKey('existing', $requestOptions); 32 | $this->assertArrayHasKey('auth', $requestOptions); 33 | $this->assertEquals($this->username . '/token', $requestOptions['auth'][0]); 34 | $this->assertEquals($this->token, $requestOptions['auth'][1]); 35 | $this->assertEquals(Auth::BASIC, $requestOptions['auth'][2]); 36 | } 37 | 38 | /** 39 | * Test the preparing of a request for oauth authentication. 40 | */ 41 | public function testPrepareOAuth() 42 | { 43 | $this->client->setAuth('oauth', ['token' => $this->oAuthToken]); 44 | 45 | $currentRequest = new Request('GET', 'http://www.endpoint.com/test.json'); 46 | $currentRequestOptions = ['existing' => 'option']; 47 | 48 | list ($request, $requestOptions) = $this->client->getAuth()->prepareRequest( 49 | $currentRequest, 50 | $currentRequestOptions 51 | ); 52 | 53 | $this->assertEquals($currentRequestOptions, $requestOptions); 54 | $this->assertNotEmpty($authHeader = $request->getHeader('Authorization')); 55 | $this->assertEquals('Bearer ' . $this->oAuthToken, $authHeader[0]); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/AutocompleteTest.php: -------------------------------------------------------------------------------- 1 | mockAPIResponses([ 19 | new Response(200, [], '') 20 | ]); 21 | 22 | $queryParams = [ 23 | 'name' => 'att' 24 | ]; 25 | 26 | $this->client->autocomplete()->tags($queryParams); 27 | 28 | $this->assertLastRequestIs( 29 | [ 30 | 'method' => 'GET', 31 | 'endpoint' => 'autocomplete/tags.json', 32 | 'queryParams' => $queryParams, 33 | ] 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/BookmarksTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->bookmarks(), 'findAll')); 19 | $this->assertTrue(method_exists($this->client->bookmarks(), 'create')); 20 | $this->assertTrue(method_exists($this->client->bookmarks(), 'delete')); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/BrandsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->brands(), 'create')); 18 | $this->assertTrue(method_exists($this->client->brands(), 'delete')); 19 | $this->assertTrue(method_exists($this->client->brands(), 'find')); 20 | $this->assertTrue(method_exists($this->client->brands(), 'findAll')); 21 | $this->assertTrue(method_exists($this->client->brands(), 'update')); 22 | } 23 | 24 | /** 25 | * Test endpoint to check host mapping is available 26 | */ 27 | public function testCheckHostMapping() 28 | { 29 | $queryParams = [ 30 | 'host_mapping' => 'test.com', 31 | 'subdomain' => 'test', 32 | ]; 33 | 34 | $this->assertEndpointCalled(function () use ($queryParams) { 35 | $this->client->brands()->checkHostMapping($queryParams); 36 | }, 'brands/check_host_mapping.json', 'GET', ['queryParams' => $queryParams]); 37 | } 38 | 39 | /** 40 | * Test updateImage method 41 | */ 42 | public function testUpdateProfileImageFromFile() 43 | { 44 | $id = 915987427; 45 | 46 | $params = [ 47 | 'file' => getcwd() . '/tests/assets/UK.png' 48 | ]; 49 | 50 | $this->assertEndpointCalled(function () use ($id, $params) { 51 | $this->client->brands($id)->updateImage($params); 52 | }, "brands/{$id}.json", 'PUT', ['multipart' => true]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/CustomRolesTest.php: -------------------------------------------------------------------------------- 1 | testResource0 = ['anyField' => 'Any field 0']; 17 | $this->testResource1 = ['anyField' => 'Any field 1']; 18 | $this->testResource2 = ['anyField' => 'Any field 2']; 19 | parent::setUp(); 20 | } 21 | 22 | public function testIterator() 23 | { 24 | // Single Page 25 | $this->mockApiResponses([ 26 | new Response(200, [], json_encode([ 27 | 'custom_roles' => [$this->testResource0, $this->testResource1, $this->testResource2] 28 | 29 | ])) 30 | ]); 31 | 32 | $iterator = $this->client->customRoles()->iterator(); 33 | 34 | $actual = iterator_to_array($iterator); 35 | $this->assertCount(3, $actual); 36 | $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); 37 | $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); 38 | $this->assertEquals($this->testResource2['anyField'], $actual[2]->anyField); 39 | } 40 | public function testRoutes() 41 | { 42 | $this->assertTrue(method_exists($this->client->customRoles(), 'findAll')); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/DummyResource.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () use ($itemId) { 19 | $this->client->dynamicContent()->items($itemId)->variants()->findAll(); 20 | }, "dynamic_content/items/{$itemId}/variants.json"); 21 | } 22 | 23 | /** 24 | * Test variant id is added to route. 25 | * 26 | * @throws \Zendesk\API\Exceptions\MissingParametersException 27 | */ 28 | public function testItemIdVariantIdIsAddedToRoute() 29 | { 30 | $itemId = 12345; 31 | $variantId = 3332; 32 | $this->assertEndpointCalled(function () use ($itemId, $variantId) { 33 | $this->client->dynamicContent()->items($itemId)->variants()->find($variantId); 34 | }, "dynamic_content/items/{$itemId}/variants/{$variantId}.json"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/GroupsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 18 | $this->client->groups()->assignable(); 19 | }, 'groups/assignable.json'); 20 | } 21 | 22 | /** 23 | * Test finding of user groups 24 | */ 25 | public function testFindUserGroups() 26 | { 27 | $this->assertEndpointCalled(function () { 28 | $this->client->users(123)->groups()->findAll(); 29 | }, 'users/123/groups.json'); 30 | } 31 | 32 | /** 33 | * Tests if the default findAll route is still accessible 34 | */ 35 | public function testFindAllGroups() 36 | { 37 | $this->assertEndpointCalled(function () { 38 | $this->client->groups()->findAll(); 39 | }, 'groups.json'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/IncrementalExportsTest.php: -------------------------------------------------------------------------------- 1 | 1332034771, 19 | ]; 20 | 21 | $this->assertEndpointCalled(function () use ($queryParams) { 22 | $this->client->incremental()->tickets($queryParams); 23 | }, 'incremental/tickets.json', 'GET', ['queryParams' => $queryParams]); 24 | } 25 | 26 | /** 27 | * Test get incremental export for ticket events 28 | * 29 | */ 30 | public function testTicketEvents() 31 | { 32 | $queryParams = [ 33 | 'start_time' => 1332034771, 34 | ]; 35 | 36 | $this->assertEndpointCalled(function () use ($queryParams) { 37 | $this->client->incremental()->ticketEvents($queryParams); 38 | }, 'incremental/ticket_events.json', 'GET', ['queryParams' => $queryParams]); 39 | } 40 | 41 | /** 42 | * Test get incremental export for organizations 43 | */ 44 | public function testOrganizations() 45 | { 46 | $queryParams = [ 47 | 'start_time' => 1332034771, 48 | ]; 49 | 50 | $this->assertEndpointCalled(function () use ($queryParams) { 51 | $this->client->incremental()->organizations($queryParams); 52 | }, 'incremental/organizations.json', 'GET', ['queryParams' => $queryParams]); 53 | } 54 | 55 | /** 56 | * Test get incremental export for users 57 | */ 58 | public function testUsers() 59 | { 60 | $queryParams = [ 61 | 'start_time' => 1332034771, 62 | ]; 63 | 64 | $this->assertEndpointCalled(function () use ($queryParams) { 65 | $this->client->incremental()->users($queryParams); 66 | }, 'incremental/users.json', 'GET', ['queryParams' => $queryParams]); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/LocalesTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 18 | $this->client->locales()->findAllPublic(); 19 | }, 'locales/public.json'); 20 | } 21 | 22 | /** 23 | * Test findAllAgent method 24 | */ 25 | public function testFindAllAgent() 26 | { 27 | $this->assertEndpointCalled(function () { 28 | $this->client->locales()->findAllAgent(); 29 | }, 'locales/agent.json'); 30 | } 31 | 32 | /** 33 | * Test findCurrent method 34 | */ 35 | public function testFindCurrent() 36 | { 37 | $this->assertEndpointCalled(function () { 38 | $this->client->locales()->findCurrent(); 39 | }, 'locales/current.json'); 40 | } 41 | 42 | /** 43 | * Test findBest method 44 | */ 45 | public function testFindBest() 46 | { 47 | $this->assertEndpointCalled(function () { 48 | $this->client->locales()->findBest(); 49 | }, 'locales/detect_best_locale.json'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/OAuthClientsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->oauthClients(), 'create')); 18 | $this->assertTrue(method_exists($this->client->oauthClients(), 'delete')); 19 | $this->assertTrue(method_exists($this->client->oauthClients(), 'find')); 20 | $this->assertTrue(method_exists($this->client->oauthClients(), 'findAll')); 21 | $this->assertTrue(method_exists($this->client->oauthClients(), 'update')); 22 | } 23 | 24 | /** 25 | * Test findAllMine method 26 | */ 27 | public function testFindAllMine() 28 | { 29 | $this->assertEndpointCalled(function () { 30 | $this->client->oauthClients()->findAllMine(); 31 | }, 'users/me/oauth/clients.json'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/OAuthTokensTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () use ($resourceId) { 19 | $this->client->oauthTokens()->revoke($resourceId); 20 | }, "oauth/tokens/{$resourceId}.json", 'DELETE'); 21 | } 22 | 23 | /** 24 | * Test for current method 25 | */ 26 | public function testCurrentEndpoint() 27 | { 28 | $this->assertEndpointCalled(function () { 29 | $this->client->oauthTokens()->current(); 30 | }, 'oauth/tokens/current.json'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/OrganizationFieldsTest.php: -------------------------------------------------------------------------------- 1 | [14382, 14342]]; 18 | 19 | $this->assertEndpointCalled(function () use ($postFields) { 20 | $this->client->organizationFields()->reorder($postFields); 21 | }, 'organization_fields/reorder.json', 'PUT', ['postFields' => $postFields]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/OrganizationSubscriptionsTest.php: -------------------------------------------------------------------------------- 1 | client->organizationSubscriptions()->getResourceName(); 18 | 19 | $this->assertEquals( 20 | 'organization_subscriptions', 21 | $resourceName, 22 | 'Should return `organization_subscriptions` as resource name' 23 | ); 24 | } 25 | 26 | /** 27 | * Test find method with chained user resource 28 | */ 29 | public function testFindUserOrganizations() 30 | { 31 | $userId = 82828; 32 | $this->assertEndpointCalled(function () use ($userId) { 33 | $this->client->users($userId)->organizationSubscriptions()->findAll(); 34 | }, "users/{$userId}/organization_subscriptions.json"); 35 | } 36 | 37 | /** 38 | * Test find method with chained organization resource 39 | */ 40 | public function testFindOrganizationSubscriptions() 41 | { 42 | $organizationId = 9393; 43 | $this->assertEndpointCalled(function () use ($organizationId) { 44 | $this->client->organizations($organizationId)->subscriptions()->findAll(); 45 | }, "organizations/{$organizationId}/subscriptions.json"); 46 | } 47 | 48 | /** 49 | * Tests if the default findAll route is still accessible 50 | */ 51 | public function testFindAllOrganizationSubscriptions() 52 | { 53 | $this->assertEndpointCalled(function () { 54 | $this->client->organizationSubscriptions()->findAll(); 55 | }, 'organization_subscriptions.json'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/OrganizationTicketsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () use ($organizationId) { 20 | $this->client->organizations($organizationId)->tickets()->findAll(); 21 | }, "organizations/{$organizationId}/tickets.json"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/PushNotificationDevicesTest.php: -------------------------------------------------------------------------------- 1 | ['token1', 'token2']]; 18 | $this->assertEndpointCalled( 19 | function () use ($postFields) { 20 | $this->client->pushNotificationDevices()->deleteMany($postFields); 21 | }, 22 | 'push_notification_devices/destroy_many.json', 23 | 'POST', 24 | [ 25 | 'postFields' => ['push_notification_devices' => $postFields['tokens']] 26 | ] 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/RequestCommentsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () use ($requestId) { 20 | $this->client->requests($requestId)->comments()->findAll(); 21 | }, "requests/{$requestId}/comments.json"); 22 | } 23 | 24 | /** 25 | * Test find method 26 | */ 27 | public function testFind() 28 | { 29 | $resourceId = 3838; 30 | $requestId = 19192; 31 | 32 | $this->assertEndpointCalled(function () use ($requestId, $resourceId) { 33 | $this->client->requests($requestId)->comments()->find($resourceId); 34 | }, "requests/{$requestId}/comments/{$resourceId}.json"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/SearchTest.php: -------------------------------------------------------------------------------- 1 | 'updated_at']; 21 | $this->assertEndpointCalled( 22 | function () use ($searchString, $queryParams) { 23 | $this->client->search()->find($searchString, $queryParams); 24 | }, 25 | 'search.json', 26 | 'GET', 27 | [ 28 | 'queryParams' => [ 29 | 'sort_by' => 'updated_at', 30 | // replace colons, the colons are a special case in this endpoint so let's do the replacement 31 | // for this test only 32 | 'query' => str_replace('%3A', ':', rawurlencode($searchString)) 33 | ] 34 | ] 35 | ); 36 | } 37 | 38 | /** 39 | * @return array 40 | */ 41 | public static function basicQueryStrings() 42 | { 43 | return [ 44 | [3245227], 45 | ['Greenbriar'], 46 | ['type:user "Jane Doe"'], 47 | ['type:ticket status:open'], 48 | ['type:organization created<2015-05-01'], 49 | ['created>2012-07-17 type:ticket organization:"MD Photo"'], 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->sharingAgreements(), 'findAll')); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/SupportAddressesTest.php: -------------------------------------------------------------------------------- 1 | 'forwarding']; 15 | 16 | $this->assertEndpointCalled(function () use ($updateData) { 17 | $this->client->supportAddresses()->verify(123, $updateData); 18 | }, 'recipient_addresses/123/verify.json', 'PUT', ['postFields' => $updateData]); 19 | } 20 | 21 | /** 22 | * Tests if the client can build the verify support address endpoint and pass the update fields 23 | */ 24 | public function testCreate() 25 | { 26 | $updateData = ['type' => 'forwarding']; 27 | 28 | $this->assertEndpointCalled(function () use ($updateData) { 29 | $this->client->supportAddresses()->create($updateData); 30 | }, 'recipient_addresses.json', 'POST', ['postFields' => ['recipient_address' => $updateData]]); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/SuspendedTicketsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->suspendedTickets(), 'delete')); 18 | $this->assertTrue(method_exists($this->client->suspendedTickets(), 'find')); 19 | $this->assertTrue(method_exists($this->client->suspendedTickets(), 'findAll')); 20 | $this->assertTrue(method_exists($this->client->suspendedTickets(), 'deleteMany')); 21 | } 22 | 23 | public function testRecover() 24 | { 25 | $resourceId = 233; 26 | $this->assertEndpointCalled( 27 | function () use ($resourceId) { 28 | $this->client->suspendedTickets($resourceId)->recover(); 29 | }, 30 | "suspended_tickets/{$resourceId}/recover.json", 31 | 'PUT' 32 | ); 33 | } 34 | 35 | public function testRecoverMany() 36 | { 37 | $resourceIds = [233, 232]; 38 | $this->assertEndpointCalled( 39 | function () use ($resourceIds) { 40 | $this->client->suspendedTickets()->recoverMany($resourceIds); 41 | }, 42 | "suspended_tickets/recover_many.json", 43 | 'PUT', 44 | ['queryParams' => ['ids' => implode(',', $resourceIds)]] 45 | ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketAuditsTest.php: -------------------------------------------------------------------------------- 1 | 1]; 23 | 24 | $this->assertEndpointCalled(function () use ($queryParams) { 25 | $this->client->tickets($this->ticketId)->audits()->findAll($queryParams); 26 | }, "tickets/{$this->ticketId}/audits.json", 'GET', ['queryParams' => $queryParams]); 27 | } 28 | 29 | /** 30 | * Test find with chained resources 31 | */ 32 | public function testFindWithChainedParams() 33 | { 34 | $auditId = 1; 35 | 36 | $this->assertEndpointCalled(function () use ($auditId) { 37 | $this->client->tickets($this->ticketId)->audits($auditId)->find(); 38 | }, "tickets/{$this->ticketId}/audits/{$auditId}.json"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketCommentsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () use ($ticketId) { 20 | $this->client->tickets($ticketId)->comments()->findAll(); 21 | }, "tickets/{$ticketId}/comments.json"); 22 | } 23 | 24 | /** 25 | * Test make private 26 | */ 27 | public function testMakePrivate() 28 | { 29 | $ticketId = 12345; 30 | $commentId = 123; 31 | $this->assertEndpointCalled(function () use ($ticketId, $commentId) { 32 | $this->client->tickets($ticketId)->comments($commentId)->makePrivate(); 33 | }, "tickets/{$ticketId}/comments/{$commentId}/make_private.json", 'PUT'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketFieldsOptionsTest.php: -------------------------------------------------------------------------------- 1 | 'one more', 22 | 'value' => 'ça bouge', 23 | ]; 24 | 25 | // FindAll 26 | $this->assertEquals( 27 | "ticket_fields/{$fieldId}/options.json", 28 | $this->client->ticketFields($fieldId)->options()->getRoute( 29 | 'findAll', 30 | ['fieldId' => $fieldId] 31 | ) 32 | ); 33 | 34 | // Create 35 | $this->assertEquals( 36 | "ticket_fields/{$fieldId}/options.json", 37 | $this->client->ticketFields($fieldId)->options()->getRoute( 38 | 'create', 39 | ['fieldId' => $fieldId] 40 | ) 41 | ); 42 | 43 | // Find 44 | $this->assertEquals( 45 | "ticket_fields/{$fieldId}/options/{$id}.json", 46 | $this->client->ticketFields($fieldId)->options($id)->getRoute( 47 | 'find', 48 | ['id' => $id, 'fieldId' => $fieldId] 49 | ) 50 | ); 51 | 52 | // Delete 53 | $this->assertEquals( 54 | "ticket_fields/{$fieldId}/options/{$id}.json", 55 | $this->client->ticketFields($fieldId)->options($id)->getRoute( 56 | 'delete', 57 | ['id' => $id, 'fieldId' => $fieldId] 58 | ) 59 | ); 60 | 61 | // Update 62 | $this->assertEquals( 63 | "ticket_fields/{$fieldId}/options.json", 64 | $this->client->ticketFields($fieldId)->options($id, $optionValues)->getRoute( 65 | 'update', 66 | ['id' => $id, 'fieldId' => $fieldId] 67 | ) 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php: -------------------------------------------------------------------------------- 1 | client); 19 | 20 | $this->assertEquals('ticket_fields', $ticketFields->getResourceName()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketFormsTest.php: -------------------------------------------------------------------------------- 1 | expectException(\Zendesk\API\Exceptions\ApiResponseException::class); 16 | $this->mockAPIResponses([ 17 | new Response(422, [], '') 18 | ]); 19 | 20 | $this->client->tickets()->forms(1)->delete(); 21 | 22 | $this->assertLastRequestIs( 23 | [ 24 | 'method' => 'DELETE', 25 | 'endpoint' => 'ticket_forms/1.json' 26 | ] 27 | ); 28 | } 29 | 30 | public function testCloneForm() 31 | { 32 | $this->mockAPIResponses([ 33 | new Response(200, [], '') 34 | ]); 35 | 36 | $this->client->tickets()->forms(1)->cloneForm(); 37 | 38 | $this->assertLastRequestIs( 39 | [ 40 | 'method' => 'POST', 41 | 'endpoint' => 'ticket_forms/1/clone.json' 42 | ] 43 | ); 44 | } 45 | 46 | /** 47 | * Tests if an exception is thrown when a ticket form ID could not be retrieved from 48 | * the method call. 49 | */ 50 | public function testCloneFormThrowsException() 51 | { 52 | $this->expectException(\Zendesk\API\Exceptions\MissingParametersException::class); 53 | $this->mockAPIResponses([ 54 | new Response(200, [], '') 55 | ]); 56 | 57 | $this->client->tickets(1)->forms()->cloneForm(); 58 | 59 | $this->assertLastRequestIs( 60 | [ 61 | 'method' => 'POST', 62 | 'endpoint' => 'ticket_forms/1/clone.json' 63 | ] 64 | ); 65 | } 66 | 67 | public function testReorder() 68 | { 69 | $this->mockAPIResponses([ 70 | new Response(200, [], '') 71 | ]); 72 | 73 | $this->client->tickets()->forms()->reorder([3, 4, 5, 1]); 74 | 75 | $this->assertLastRequestIs( 76 | [ 77 | 'method' => 'PUT', 78 | 'endpoint' => 'ticket_forms/reorder.json', 79 | 'postFields' => ['ticket_form_ids' => [3, 4, 5, 1]] 80 | ] 81 | ); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketImportsTest.php: -------------------------------------------------------------------------------- 1 | client->ticketImports()->getRoutes(); 18 | 19 | $this->assertEquals('imports/tickets.json', $routes['create']); 20 | $this->assertEquals('imports/tickets/create_many.json', $routes['createMany']); 21 | $this->assertEquals(2, count($routes), 'Should only have routes for create and createMany'); 22 | } 23 | 24 | /** 25 | * Test that the trait methods exists 26 | */ 27 | public function testTraitMethods() 28 | { 29 | $this->assertTrue(method_exists($this->client->ticketImports(), 'create')); 30 | $this->assertTrue(method_exists($this->client->ticketImports(), 'createMany')); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TicketMetricsTest.php: -------------------------------------------------------------------------------- 1 | client->tickets(12345)->metrics()->getRoute('find', ['id' => 12345]); 22 | $this->assertEquals('tickets/12345/metrics.json', $route); 23 | 24 | $route = $this->client->tickets()->metrics(12345)->getRoute('find', ['id' => 12345]); 25 | $this->assertEquals('ticket_metrics/12345.json', $route); 26 | 27 | $route = $this->client->tickets()->metrics()->getRoute('findAll'); 28 | $this->assertEquals('ticket_metrics.json', $route); 29 | 30 | $route = $this->client->tickets(12345)->metrics()->getRoute('findAll'); 31 | $this->assertEquals('tickets/12345/metrics.json', $route); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TranslationsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 18 | $this->client->translations()->manifest(); 19 | }, 'translations/manifest.json'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TriggersTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 18 | $this->client->triggers()->findActive(); 19 | }, 'triggers/active.json'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/TwitterHandlesTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 15 | $this->client->twitterHandles()->findAll(); 16 | }, 'channels/twitter/monitored_twitter_handles.json'); 17 | 18 | $this->assertEndpointCalled(function () { 19 | $this->client->twitterHandles()->find(1); 20 | }, 'channels/twitter/monitored_twitter_handles/1.json'); 21 | } 22 | 23 | /** 24 | * Test that only find and findAll are present 25 | */ 26 | public function testMethods() 27 | { 28 | $this->assertFalse(method_exists($this->client->twitterHandles(), 'create')); 29 | $this->assertFalse(method_exists($this->client->twitterHandles(), 'delete')); 30 | $this->assertFalse(method_exists($this->client->twitterHandles(), 'update')); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/UserFieldsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () use ($ids) { 20 | $this->client->userFields()->reorder($ids); 21 | }, 'user_fields/reorder.json', 'PUT', ['postFields' => ['user_field_ids' => $ids]]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/UserTicketsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 20 | $this->client->users(12345)->tickets()->requested(); 21 | }, 'users/12345/tickets/requested.json'); 22 | } 23 | 24 | /** 25 | * Tests if the requested endpoint can be called by the client and is passed the correct ID 26 | */ 27 | public function testCCD() 28 | { 29 | $this->assertEndpointCalled(function () { 30 | $this->client->users(12345)->tickets()->ccd(); 31 | }, 'users/12345/tickets/ccd.json'); 32 | } 33 | 34 | /** 35 | * Tests if the requested endpoint can be called by the client and is passed the correct ID 36 | */ 37 | public function testAssigned() 38 | { 39 | $this->assertEndpointCalled(function () { 40 | $this->client->users(12345)->tickets()->assigned(); 41 | }, 'users/12345/tickets/assigned.json'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Core/WebhooksTest.php: -------------------------------------------------------------------------------- 1 | 'somerule', 20 | ]; 21 | 22 | // We expect invalid parameters are removed. 23 | // We also expect url encoded keys and values 24 | $expectedQueryParams = []; 25 | foreach ($queryParams as $key => $value) { 26 | $expectedQueryParams = array_merge($expectedQueryParams, [urlencode($key) => $value]); 27 | } 28 | 29 | $this->assertEndpointCalled( 30 | function () use ($queryParams) { 31 | $this->client->webhooks()->findAll($queryParams); 32 | }, 33 | 'webhooks', 34 | 'GET', 35 | ['queryParams' => $expectedQueryParams] 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Embeddable/ConfigSetsTest.php: -------------------------------------------------------------------------------- 1 | $faker->hexColor, 18 | 'position' => $faker->randomElement(['left', 'right']), 19 | ]; 20 | 21 | $this->assertEndpointCalled(function () use ($params) { 22 | $this->client->embeddable->configSets()->create($params); 23 | }, 'api/v2/embeddable/api/config_sets.json', 'POST', [ 24 | 'apiBasePath' => '/', 25 | 'postFields' => ['config_set' => $params], 26 | ]); 27 | } 28 | 29 | /** 30 | * Tests if the client can call and build the update config sets endpoint 31 | */ 32 | public function testUpdate() 33 | { 34 | $faker = Factory::create(); 35 | $id = $faker->numberBetween(1); 36 | $params = [ 37 | 'color' => $faker->hexColor, 38 | 'position' => $faker->randomElement(['left', 'right']), 39 | ]; 40 | 41 | $this->assertEndpointCalled(function () use ($params, $id) { 42 | $this->client->embeddable->configSets()->update($id, $params); 43 | }, "api/v2/embeddable/api/config_sets/{$id}.json", 'PUT', [ 44 | 'apiBasePath' => '/', 45 | 'postFields' => ['config_set' => $params], 46 | ]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php: -------------------------------------------------------------------------------- 1 | "application/json"], ""); 18 | $requestException = new ServerException("test", $request, $response); 19 | 20 | $subject = new ApiResponseException($requestException); 21 | 22 | $this->assertEquals([], $subject->getErrorDetails()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Sell/ContactsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(method_exists($this->client->sell->contacts(), 'create')); 16 | $this->assertTrue(method_exists($this->client->sell->contacts(), 'delete')); 17 | $this->assertTrue(method_exists($this->client->sell->contacts(), 'find')); 18 | $this->assertTrue(method_exists($this->client->sell->contacts(), 'findAll')); 19 | $this->assertTrue(method_exists($this->client->sell->contacts(), 'update')); 20 | $this->assertTrue(method_exists($this->client->sell->contacts(), 'upsert')); 21 | } 22 | 23 | /** 24 | * Tests if the upsert endpoint can be called and passed the correct params 25 | */ 26 | public function testUpsert() 27 | { 28 | $faker = Factory::create(); 29 | 30 | $queryParams = [ 31 | 'email' => $faker->email, 32 | 'phone' => $faker->phoneNumber, 33 | ]; 34 | 35 | $postFields = [ 36 | 'email' => $faker->email, 37 | 'custom_fields' => [ 38 | 'Some Field' => $faker->text 39 | ] 40 | ]; 41 | 42 | $encodedQueryParams = []; 43 | foreach ($queryParams as $key => $value) { 44 | // Encode the 'phone' query param's whitespace 45 | if ($key === 'phone') { 46 | $value = str_replace(' ', '%20', $value); 47 | } 48 | $encodedQueryParams[$key] = $value; 49 | } 50 | 51 | $this->assertEndpointCalled(function () use ($queryParams, $postFields) { 52 | $this->client->sell->contacts()->upsert($queryParams, $postFields); 53 | }, '/contacts/upsert', 'POST', [ 54 | 'queryParams' => $encodedQueryParams, 55 | 'postFields' => ['data' => $postFields], 56 | 'apiBasePath' => '/v2' 57 | ]); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Talk/StatsTest.php: -------------------------------------------------------------------------------- 1 | assertEndpointCalled(function () { 17 | $this->client->talk->stats()->currentQueue(); 18 | }, 'channels/voice/stats/current_queue_activity.json', 'GET'); 19 | } 20 | 21 | /** 22 | * Tests if the account overview endpoint can be called and passed the correct params 23 | */ 24 | public function testAccountOverview() 25 | { 26 | $this->assertEndpointCalled(function () { 27 | $this->client->talk->stats()->accountOverview(); 28 | }, 'channels/voice/stats/account_overview.json', 'GET'); 29 | } 30 | 31 | /** 32 | * Tests if the agents overview endpoint can be called and passed the correct params 33 | */ 34 | public function testAgentsOverview() 35 | { 36 | $this->assertEndpointCalled(function () { 37 | $this->client->talk->stats()->agentsOverview(); 38 | }, 'channels/voice/stats/agents_overview.json', 'GET'); 39 | } 40 | 41 | /** 42 | * Tests if the agents activity endpoint can be called and passed the correct params 43 | */ 44 | public function testAgentsActivity() 45 | { 46 | $this->assertEndpointCalled(function () { 47 | $this->client->talk->stats()->agentsActivity(); 48 | }, 'channels/voice/stats/agents_activity.json', 'GET'); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Utilities/OAuthTest.php: -------------------------------------------------------------------------------- 1 | 'test_client', 18 | 'state' => 'St8fulbar', 19 | ]; 20 | 21 | $expected = 'https://z3ntestsub.zendesk.com/oauth/authorizations/new?response_type=code&client_id=test_client&state=St8fulbar&scope=read+write'; 22 | 23 | $this->assertEquals($expected, OAuth::getAuthUrl('z3ntestsub', $params)); 24 | } 25 | 26 | public function testAccessTokenIsRequested() 27 | { 28 | $this->mockApiResponses([ 29 | new Response(200, [], json_encode(['access_token' => 12345])) 30 | ]); 31 | 32 | $params = [ 33 | 'code' => 'adwo123ijo', 34 | 'client_id' => 'test_client', 35 | 'client_secret' => 'dwapjoJ123d8w9a01-', 36 | 'grant_type' => 'authorization_code', 37 | 'scope' => 'read write', 38 | 'redirect_uri' => 'https://test.foo.com', 39 | ]; 40 | 41 | OAuth::getAccessToken($this->client->guzzle, 'test', $params); 42 | 43 | $this->assertLastRequestIs([ 44 | 'method' => 'POST', 45 | 'requestUri' => 'https://test.zendesk.com/oauth/tokens', 46 | 'postFields' => $params, 47 | 'headers' => [ 48 | 'accept' => false, 49 | ], 50 | 'apiBasePath' => '/', 51 | ]); 52 | } 53 | 54 | /** 55 | * Tests if the OAuth::getAuthUrl function returns a correct URL. 56 | */ 57 | public function testConfigurableDomain() 58 | { 59 | $params = [ 60 | 'client_id' => 'test_client', 61 | 'state' => 'St8fulbar', 62 | ]; 63 | 64 | $expected = 'https://z3ntestsub.testDomain.com/oauth/authorizations/new?response_type=code&client_id=test_client&state=St8fulbar&scope=read+write'; 65 | 66 | $this->assertEquals($expected, OAuth::getAuthUrl('z3ntestsub', $params, 'testDomain.com')); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/VersionTest.php: -------------------------------------------------------------------------------- 1 | word); 23 | 24 | $this->assertEquals("ZendeskAPI PHP {$fileVersion}", $client->getUserAgent()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Zendesk/API/UnitTests/Voice/PhoneNumbersTest.php: -------------------------------------------------------------------------------- 1 | 'US', 16 | 'area_code' => 410, 17 | 'contains' => 'pizza', 18 | 'toll_free' => 1, 19 | ]; 20 | 21 | $this->assertEndpointCalled(function () use ($queryParams) { 22 | $this->client->voice->phoneNumbers()->search($queryParams); 23 | }, 'channels/voice/phone_numbers/search.json', 'GET', ['queryParams' => $queryParams]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/assets/UK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/zendesk_api_client_php/a6d5fc39c46c63a79578ed6b47635271c401fb2b/tests/assets/UK.png -------------------------------------------------------------------------------- /tests/assets/app.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/zendesk_api_client_php/a6d5fc39c46c63a79578ed6b47635271c401fb2b/tests/assets/app.zip -------------------------------------------------------------------------------- /tests/assets/ga4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/zendesk_api_client_php/a6d5fc39c46c63a79578ed6b47635271c401fb2b/tests/assets/ga4.png -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | add('Zendesk\\API\\LiveTests\\', __DIR__); 12 | $loader->add('Zendesk\\API\\UnitTests\\', __DIR__); 13 | -------------------------------------------------------------------------------- /tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/zendesk_api_client_php/a6d5fc39c46c63a79578ed6b47635271c401fb2b/tmp/.gitkeep --------------------------------------------------------------------------------