├── .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 |
"; 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 | '