├── .env.test
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── pull_request_template.md
├── release-drafter.yml
└── workflows
│ ├── ci-cd.yml
│ ├── deploy.yml
│ └── release-drafter.yml
├── .gitignore
├── .npmignore
├── .travis.yml
├── .xo-config.json
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── ReadMe.md
├── SECURITY.md
├── docs
├── .vitepress
│ └── config.mts
├── guide
│ ├── Guide
│ │ ├── Advanced
│ │ │ ├── custom-headers.md
│ │ │ ├── custom-logging.md
│ │ │ ├── custom-transport.md
│ │ │ ├── debugging.md
│ │ │ ├── endpoint-override.md
│ │ │ ├── index.md
│ │ │ ├── manage-apis.md
│ │ │ ├── pagination.md
│ │ │ ├── sideload.md
│ │ │ └── throttling.md
│ │ ├── authentication.md
│ │ ├── final.md
│ │ └── installation.md
│ └── index.md
├── index.md
├── old
│ ├── api-coverage.md
│ ├── future-features.md
│ ├── meetings
│ │ └── 2015-05-09.md
│ └── side-loading.md
└── public
│ └── Node_Zendesk_logo.svg
├── examples
├── activities-list.js
├── automations-list.js
├── busey.gif
├── check-auth-promise.js
├── check-auth-token.js
├── check-auth.js
├── check-oauth-token.js
├── create-oauth-token.js
├── delete-many-organizations.js
├── endpoint.js
├── example-config.js
├── groupmemberships-list-group.js
├── groupmemberships-list-user.js
├── groupmemberships-list.js
├── groups-list-assignable.js
├── groups-list.js
├── macros-active-list.js
├── optional-axios-transport.js
├── optional-deprecated-request-transport.js
├── organization-fields-list.js
├── organization-memberships-list.js
├── organization-upsert.js
├── organizations-delete-bulk.js
├── organizations-delete.js
├── organizations-list.js
├── search-query.js
├── suspended-tickets-list.js
├── tags-list.js
├── ticket-create-promise.js
├── ticket-create.js
├── ticket-delete.js
├── ticket-list-observer.js
├── ticket-list.js
├── ticketaudits-list.js
├── ticketmetric-list.js
├── triggers-list.js
├── upload-attachment.js
├── user-create-many.js
├── user-create-promise.js
├── user-create.js
├── user-fields-list.js
├── users-list.js
├── users-listbygroup.js
├── usertags-list.js
└── views-list.js
├── package-lock.json
├── package.json
├── src
├── clients
│ ├── authorization-handler.js
│ ├── client.js
│ ├── core
│ │ ├── accountsettings.js
│ │ ├── activitystream.js
│ │ ├── attachments.js
│ │ ├── automations.js
│ │ ├── brand.js
│ │ ├── customagentroles.js
│ │ ├── dynamiccontent.js
│ │ ├── dynamiccontentvariants.js
│ │ ├── groupmemberships.js
│ │ ├── groups.js
│ │ ├── imports.js
│ │ ├── installations.js
│ │ ├── jobstatuses.js
│ │ ├── locales.js
│ │ ├── macros.js
│ │ ├── oauthclients.js
│ │ ├── oauthtokens.js
│ │ ├── organizationfields.js
│ │ ├── organizationmemberships.js
│ │ ├── organizations.js
│ │ ├── permissiongroups.js
│ │ ├── policies.js
│ │ ├── requests.js
│ │ ├── satisfactionratings.js
│ │ ├── search.js
│ │ ├── sessions.js
│ │ ├── sharingagreement.js
│ │ ├── sideconversations.js
│ │ ├── suspendedtickets.js
│ │ ├── tags.js
│ │ ├── targetfailures.js
│ │ ├── targets.js
│ │ ├── ticketaudits.js
│ │ ├── ticketevents.js
│ │ ├── ticketexport.js
│ │ ├── ticketfields.js
│ │ ├── ticketforms.js
│ │ ├── ticketimport.js
│ │ ├── ticketmetrics.js
│ │ ├── tickets.js
│ │ ├── triggers.js
│ │ ├── userfields.js
│ │ ├── useridentities.js
│ │ ├── users.js
│ │ ├── views.js
│ │ └── webhooks.js
│ ├── custom-event-target.js
│ ├── endpoint-checker.js
│ ├── helpcenter
│ │ ├── accesspolicies.js
│ │ ├── articleattachments.js
│ │ ├── articlecomments.js
│ │ ├── articlelabels.js
│ │ ├── articles.js
│ │ ├── categories.js
│ │ ├── index.js
│ │ ├── search.js
│ │ ├── sections.js
│ │ ├── subscriptions.js
│ │ ├── translations.js
│ │ ├── usersegments.js
│ │ └── votes.js
│ ├── helpers.js
│ ├── job-monitor.js
│ ├── services
│ │ ├── index.js
│ │ └── links.js
│ ├── throttle.js
│ ├── transporter.js
│ └── voice
│ │ ├── agentactivity.js
│ │ ├── availabilities.js
│ │ ├── currentqueueactivity.js
│ │ ├── greetingcategories.js
│ │ ├── greetings.js
│ │ ├── historicalqueueactivity.js
│ │ ├── index.js
│ │ └── phonenumbers.js
├── constants.js
├── index.js
└── logger.js
└── test
├── authentication.test.js
├── endpoint-checker.test.js
├── exceptionshandling.test.js
├── fixtures
├── authentication_test_correct_oauthtoken.json
├── authentication_test_correct_u_token.json
├── authentication_test_endpoint_uri.json
├── authentication_test_incorrect_sans_token.json
├── authentication_test_incorrect_subdomain.json
├── authentication_test_incorrect_token.json
├── authentication_test_incorrect_u_p.json
├── authentication_test_no_creds.json
├── authentication_test_user_pass.json
├── organizations_many_test_bulk_delete.json
├── organizations_many_test_create_multiple.json
├── organizations_many_test_update_multiple.json
├── organizations_test_autocomplete_organization.json
├── organizations_test_create.json
├── organizations_test_delete_not_found_organization.json
├── organizations_test_delete_organization.json
├── organizations_test_list_all.json
├── organizations_test_search_organization.json
├── organizations_test_show_single.json
├── organizations_test_update_organization.json
├── pagination_test_cleanup.json
├── pagination_test_execute.json
├── pagination_test_setup.json
└── webhooks_endpoint.json
├── job-runner.js
├── node-zendesk-tests.js
├── organizations.many.test.js
├── organizations.test.js
├── pagination.test.js
├── setup.js
└── webhooks.test.js
/.env.test:
--------------------------------------------------------------------------------
1 | # .env
2 |
3 | # Zendesk authentication details
4 | ZENDESK_FULL_NAME="TEST USER"
5 | ZENDESK_USERNAME=myUsername
6 | ZENDESK_TOKEN=myToken
7 | ZENDESK_PASSWORD=myPassword
8 | ZENDESK_SUBDOMAIN=nodejsapi
9 | ZENDESK_OAUTH_ACCESS_TOKEN=myOAuthAccessToken
10 | ZENDESK_ENDPOINT_URI=https://nodejsapi.zendesk.com/api/v2
11 |
12 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: blakmatrix
4 | open_collective: node-zendesk
5 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the Bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **Example Code**
14 | ```javascript
15 | // Your example code that produces the issue goes here
16 | ```
17 |
18 | **Expected Behavior**
19 | A clear and concise description of what you expected to happen.
20 |
21 | **Actual Behavior**
22 | What actually happened. If applicable, add screenshots or error messages to help explain the problem.
23 |
24 | **Environment Information**
25 | - `node-zendesk` version:
26 | - Node.js version:
27 | - Operating System:
28 | - Any other relevant software versions?
29 |
30 | **Additional Context**
31 | Add any other context about the problem here.
32 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea or enhancement for this project
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Feature Description**
11 | Briefly describe the feature you'd like to see implemented.
12 |
13 | **Example Use Case**
14 | Provide an example or context where this feature would be beneficial.
15 |
16 | **Additional Information**
17 | Any other details or ideas related to the feature.
18 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Pull Request Description
2 |
3 | Please provide a brief description of your changes.
4 |
5 | ---
6 |
7 | ## Related Issue(s)
8 |
9 | - [ ] This PR fixes/closes issue #...
10 | - [ ] This is a new feature and does not have an associated issue.
11 |
12 | ---
13 |
14 | ## Additional Information
15 |
16 | - [ ] This change is a breaking change (may require a major version update)
17 | - [ ] This change is a new feature (non-breaking change which adds functionality)
18 | - [ ] This change improves the code (e.g., refactoring, etc.)
19 | - [ ] This change includes dependency updates
20 |
21 | ---
22 |
23 | ## Test Cases
24 |
25 | Include any test cases or steps you took to test your changes. If you have added new functionality, please include relevant unit tests.
26 |
27 | ---
28 |
29 | ## Documentation
30 |
31 | - [ ] I have updated the documentation accordingly.
32 | - [ ] No updates are required.
33 |
34 | ---
35 |
36 | ## Checklist
37 |
38 | - [ ] I have read the [CONTRIBUTING](./CONTRIBUTING.md) documentation.
39 | - [ ] My code follows the coding standards of this project.
40 | - [ ] All new and existing tests passed.
41 |
42 |
--------------------------------------------------------------------------------
/.github/release-drafter.yml:
--------------------------------------------------------------------------------
1 | name-template: 'v$NEXT_PATCH_VERSION 🌈'
2 | tag-template: 'v$NEXT_PATCH_VERSION'
3 | categories:
4 | - title: '🚀 Features'
5 | labels:
6 | - 'feature'
7 | - 'enhancement'
8 | - title: '🐛 Bug Fixes'
9 | labels:
10 | - 'fix'
11 | - 'bugfix'
12 | - 'bug'
13 | - title: '🧰 Maintenance'
14 | label: 'chore'
15 | change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
16 | exclude-labels:
17 | - 'skip-changelog'
18 | template: |
19 | ## Changes
20 |
21 | $CHANGES
22 |
--------------------------------------------------------------------------------
/.github/workflows/ci-cd.yml:
--------------------------------------------------------------------------------
1 | name: Continuous Integration and Deployment
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | # Combined CI and CD Jobs to reduce redundancy
11 | build-and-deploy:
12 | runs-on: ubuntu-latest
13 |
14 | # Sets permissions for the GITHUB_TOKEN
15 | permissions:
16 | contents: read
17 | pages: write
18 | id-token: write
19 |
20 | steps:
21 | # Checkout code just once
22 | - uses: actions/checkout@v3
23 |
24 | # Setup Node.js only once
25 | - name: Setup Node.js
26 | uses: actions/setup-node@v3
27 | with:
28 | node-version: 22
29 | cache: 'npm'
30 |
31 | # Install dependencies only once
32 | - name: Install Dependencies
33 | run: npm ci
34 |
35 | # Lint, Test, Build, and Generate Documentation
36 | - name: Lint
37 | run: npm run lint
38 |
39 | - name: Test
40 | run: npm run test
41 |
42 | - name: Build
43 | run: npm run build
44 |
45 | - name: Generate Documentation
46 | run: npm run docs:code
47 | env:
48 | NODE_OPTIONS: --max-old-space-size=4096
49 | NO_COLOR: true
50 |
51 | # Conditional Deployment steps
52 | - name: Setup Pages
53 | if: github.event_name == 'push' && github.ref == 'refs/heads/master'
54 | uses: actions/configure-pages@v3
55 |
56 | - name: Build with VitePress
57 | if: github.event_name == 'push' && github.ref == 'refs/heads/master'
58 | run: npm run docs:deploy-github-pages
59 |
60 | - name: Upload artifact
61 | if: github.event_name == 'push' && github.ref == 'refs/heads/master'
62 | uses: actions/upload-pages-artifact@v2
63 | with:
64 | path: docs/.vitepress/dist
65 |
66 | - name: Deploy to GitHub Pages
67 | if: github.event_name == 'push' && github.ref == 'refs/heads/master'
68 | uses: actions/deploy-pages@v2
69 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | # Sample workflow for building and deploying a VitePress site to GitHub Pages
2 | #
3 | name: Deploy VitePress site to Pages
4 |
5 | on:
6 | # Runs on pushes targeting the `main` branch. Change this to `master` if you're
7 | # using the `master` branch as the default branch.
8 | # push:
9 | # branches: [master]
10 |
11 | # Allows you to run this workflow manually from the Actions tab
12 | workflow_dispatch:
13 |
14 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15 | permissions:
16 | contents: read
17 | pages: write
18 | id-token: write
19 |
20 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
21 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
22 | concurrency:
23 | group: pages
24 | cancel-in-progress: false
25 |
26 | jobs:
27 | # Build job
28 | build:
29 | runs-on: ubuntu-latest
30 | steps:
31 | - name: Checkout
32 | uses: actions/checkout@v3
33 | with:
34 | fetch-depth: 0 # Not needed if lastUpdated is not enabled
35 | # - uses: pnpm/action-setup@v2 # Uncomment this if you're using pnpm
36 | # - uses: oven-sh/setup-bun@v1 # Uncomment this if you're using Bun
37 | - name: Setup Node
38 | uses: actions/setup-node@v3
39 | with:
40 | node-version: 22
41 | cache: npm # or pnpm / yarn
42 | - name: Setup Pages
43 | uses: actions/configure-pages@v3
44 | - name: Install dependencies
45 | run: npm ci # or pnpm install / yarn install / bun install
46 | - name: Build with VitePress
47 | run: |
48 | npm run docs:deploy-github-pages
49 | - name: Upload artifact
50 | uses: actions/upload-pages-artifact@v2
51 | with:
52 | path: docs/.vitepress/dist
53 |
54 | # Deployment job
55 | deploy:
56 | environment:
57 | name: github-pages
58 | url: ${{ steps.deployment.outputs.page_url }}
59 | needs: build
60 | runs-on: ubuntu-latest
61 | name: Deploy
62 | steps:
63 | - name: Deploy to GitHub Pages
64 | id: deployment
65 | uses: actions/deploy-pages@v2
66 |
--------------------------------------------------------------------------------
/.github/workflows/release-drafter.yml:
--------------------------------------------------------------------------------
1 | name: Release Drafter
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | jobs:
8 | release-drafter:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: release-drafter/release-drafter@v5
12 | env:
13 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 | .pnpm-debug.log*
9 |
10 | # Diagnostic reports (https://nodejs.org/api/report.html)
11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12 |
13 | # Runtime data
14 | pids
15 | *.pid
16 | *.seed
17 | *.pid.lock
18 |
19 | # Dependency directories
20 | node_modules/
21 | jspm_packages/
22 |
23 | # Optional npm cache directory
24 | .npm
25 |
26 | # Optional REPL history
27 | .node_repl_history
28 |
29 | # Output of 'npm pack'
30 | *.tgz
31 |
32 | # Others
33 | .DS_Store
34 | *.iml
35 | *.ipr
36 | *.iws
37 | /.idea
38 | .vscode
39 |
40 | # dotenv environment variable files
41 | .env
42 | .env.development.local
43 | .env.test.local
44 | .env.production.local
45 | .env.local
46 |
47 | # vitepress build/dev output
48 | docs/.vitepress/dist
49 | docs/.vitepress/cache
50 | docs/.vitepress/.temp
51 | docs/api/
52 | docs/code/
53 |
54 | # vitest
55 | coverage/
56 |
57 | dist/
58 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | npm-debug.log
3 | node_modules
4 | examples/
5 | .github/
6 | .vscode/
7 | .travis.yml
8 | coverage/
9 | test/
10 | docs/
11 | doc/
12 | CODE_OF_CONDUCT.md
13 | CONTRIBUTING.md
14 | deploy.docs.*
15 | SECURITY.md
16 | .env
17 | .env.example
18 | .xo-config.json
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | branches:
3 | only:
4 | - master
5 | node_js:
6 | - 0.10
7 |
8 | notifications:
9 | email:
10 | - blakmatrix@gmail.com
11 |
--------------------------------------------------------------------------------
/.xo-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugin": ["jsdoc"],
3 | "prettier": true,
4 | "space": 2,
5 | "rules": {
6 | "jsdoc/check-access": 1,
7 | "jsdoc/check-alignment": 1,
8 | "jsdoc/check-param-names": 1,
9 | "jsdoc/check-property-names": 1,
10 | "jsdoc/check-tag-names": 1,
11 | "jsdoc/check-types": 1,
12 | "jsdoc/check-values": 1,
13 | "jsdoc/empty-tags": 1,
14 | "jsdoc/implements-on-classes": 1,
15 | "jsdoc/multiline-blocks": 1,
16 | "jsdoc/no-multi-asterisks": 1,
17 | "jsdoc/no-undefined-types": 1,
18 | "jsdoc/require-jsdoc": 1,
19 | "jsdoc/require-param": 1,
20 | "jsdoc/require-param-description": 1,
21 | "jsdoc/require-param-name": 1,
22 | "jsdoc/require-param-type": 1,
23 | "jsdoc/require-property": 1,
24 | "jsdoc/require-property-description": 1,
25 | "jsdoc/require-property-name": 1,
26 | "jsdoc/require-property-type": 1,
27 | "jsdoc/require-returns": 1,
28 | "jsdoc/require-returns-check": 1,
29 | "jsdoc/require-returns-description": 1,
30 | "jsdoc/require-returns-type": 1,
31 | "jsdoc/require-yields": 1,
32 | "jsdoc/require-yields-check": 1,
33 | "jsdoc/sort-tags": 1,
34 | "jsdoc/tag-lines": 1,
35 | "jsdoc/valid-types": 1,
36 |
37 | "unicorn/prefer-module": "off",
38 | "unicorn/prefer-top-level-await": "off",
39 | "import/extensions": "off",
40 | "no-multi-assign": "off",
41 | "camelcase": [
42 | "warn",
43 | {
44 | "allow": [
45 | "automation_ids",
46 | "label_names",
47 | "phone_number",
48 | "previous_password",
49 | "start_time",
50 | "ticket_ids",
51 | "trigger_ids",
52 | "host_mapping",
53 | "malware_access_override",
54 | "group_memberships",
55 | "available_locales",
56 | "organization_field_ids",
57 | "external_id",
58 | "sla_policy_ids",
59 | "job_status",
60 | "sharing_agreement",
61 | "prepend_clone_title",
62 | "ticket_form_ids",
63 | "user_field_ids",
64 | "view_order",
65 | "custom_role",
66 | "http_method",
67 | "request_format",
68 | "client_id",
69 | "organization_membership",
70 | "organization_memberships"
71 | ]
72 | }
73 | ]
74 | }
75 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | ## Being Considerate as Contributors
2 |
3 | We ask all contributors to this project to be mindful of others and make meaningful additions. Though there is no formal code, we trust that everyone will interact thoughtfully, with patience, good faith, and kindness. If you have any concerns, please contact the maintainers.
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to `node-zendesk`
2 |
3 | First and foremost, thank you! We appreciate that you want to contribute to `node-zendesk`. Your time is valuable, and your contributions mean a lot to us.
4 |
5 | ## Getting Started
6 |
7 | - **Fork the repository** and clone it locally. Connect your local repository to the original `node-zendesk` repository by adding it as an upstream remote:
8 |
9 | ```
10 | git clone https://github.com/[your-username]/node-zendesk.git
11 | git remote add upstream https://github.com/blakmatrix/node-zendesk.git
12 | ```
13 |
14 | - **Install the dependencies**:
15 |
16 | ```
17 | npm install
18 | ```
19 |
20 | ## How to Contribute
21 |
22 | 1. **Find an issue to work on**. Check out the open [issues](https://github.com/blakmatrix/node-zendesk/issues) or create a new one describing a feature, bug, or other project-related task. ( Check out the [API Coverage Document](https://github.com/blakmatrix/node-zendesk/blob/master/doc/api-coverage.md) for ideas)
23 |
24 | 2. **Work on your feature or bugfix**. Ensure your code is clean and well-documented. Adhere to the project's coding style.
25 |
26 | 3. **Write tests**. If you're adding a new feature, make sure you add relevant tests. If you're fixing a bug, try to write a test that would have caught the bug.
27 |
28 | 4. **Create a pull request**. Push to your fork and [submit a pull request](https://github.com/blakmatrix/node-zendesk/pulls) to the main `node-zendesk` repository. Describe your changes comprehensively.
29 |
30 | 5. **Wait for the review**. The maintainers will review your PR, suggest changes if necessary, and merge it once it's approved.
31 |
32 | ## Coding Style
33 |
34 | - We use the `xo` package as our JavaScript/TypeScript linter. Please ensure your code conforms to the linter's rules. You can check your code with `xo` by running:
35 |
36 | ```
37 | npm run lint
38 | ```
39 |
40 | - For those who prefer integrating the linter into their editors, [`xo` offers editor plugins](https://github.com/xojs/xo/tree/main#editor-plugins) for smoother development.
41 |
42 | - Use clear and meaningful variable and function names.
43 | - Include comments and keep your code as readable as possible.
44 |
45 | ## Documentation Reference
46 |
47 | - Zendesk's documentation can be found [here](https://developer.zendesk.com/rest_api/docs/core/introduction).
48 |
49 | ## Communication
50 |
51 | - If you have a question or need assistance, feel free to open an issue or email blakmatrix@gmail.com.
52 |
53 | ## Thanks Again!
54 |
55 | Thank you for your contribution! By participating in this project, you agree to abide by its terms and the expectations set in the Code of Conduct.
56 |
57 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2012-2023 Farrin Reid
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | Only the latest version of `node-zendesk` is currently being supported with security updates.
6 |
7 | | Version | Supported |
8 | | --------- | ------------------ |
9 | | latest | :white_check_mark: |
10 | | < latest | :x: |
11 |
12 | ## Reporting a Vulnerability
13 |
14 | If you believe you've found a security vulnerability in `node-zendesk`, please send an email to [blakmatrix@gmail.com](mailto:blakmatrix@gmail.com) detailing the suspected issue. Do **not** open a public GitHub issue if the bug is a security vulnerability.
15 |
16 | ### What to include in your report
17 |
18 | To help us understand the scope and impact of the security issue, please include as much detail as possible. This might include:
19 |
20 | - Steps to reproduce the issue, ideally a minimized test case.
21 | - Your expected result.
22 | - Your observed result.
23 |
24 | ### What to expect
25 |
26 | After you've submitted a vulnerability report:
27 |
28 | - We will acknowledge receipt of your vulnerability report.
29 | - We'll do our best to validate the reported vulnerability.
30 | - If valid, please understand that `node-zendesk` is a labor of love and maintained without any sponsorship(yet). While we always aim to address vulnerabilities as quickly as possible, it might take some time depending on the availability of maintainers.
31 | - Once resolved, we will provide an update on the report and possible mention in release notes (if you agree).
32 |
33 | Thank you for helping to improve `node-zendesk` and for your patience.
34 |
--------------------------------------------------------------------------------
/docs/.vitepress/config.mts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vitepress'
2 | import { generateSidebar } from "vitepress-sidebar";
3 |
4 |
5 |
6 | const getSideBar = (): any => {
7 | const generatedSidebar = generateSidebar([
8 | {
9 | documentRootPath: "docs",
10 | scanStartPath: "guide",
11 | resolvePath: "/guide/",
12 | useTitleFromFileHeading: true,
13 | hyphenToSpace: true,
14 | keepMarkdownSyntaxFromTitle: true,
15 | manualSortFileNameByPriority: [ "installation.md", "authentication.md", "final.md" , 'Advanced']
16 | },
17 | {
18 | documentRootPath: "docs",
19 | scanStartPath: "code",
20 | resolvePath: "/code/",
21 | useTitleFromFileHeading: true,
22 | hyphenToSpace: true,
23 | keepMarkdownSyntaxFromTitle: true,
24 | },
25 | ]);
26 | return generatedSidebar ?? [];
27 | };
28 |
29 | // https://vitepress.dev/reference/site-config
30 | export default defineConfig({
31 | title: "node-zendesk",
32 | description: "A Zendesk API client wrapper",
33 | base: "/node-zendesk/",
34 | themeConfig: {
35 | // https://vitepress.dev/reference/default-theme-config
36 | logo: '/Node_Zendesk_logo.svg',
37 | nav: [
38 | { text: "Home", link: "/" },
39 | { text: "Guide", link: "/guide/" },
40 | { text: "API Example", link: "/code/README" },
41 | ],
42 |
43 | sidebar: getSideBar(),
44 | outline: { level: [2, 6] },
45 |
46 | search: {
47 | provider: 'local'
48 | },
49 |
50 | socialLinks: [
51 | { icon: 'github', link: 'https://github.com/blakmatrix/node-zendesk' }
52 | ],
53 | footer: {
54 | message: 'Released under the MIT License.',
55 | copyright: 'Copyright © 2012-present | Made by Farrin A. Reid with ❤️'
56 | },
57 | },
58 | })
59 |
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/custom-headers.md:
--------------------------------------------------------------------------------
1 | # Custom Headers
2 |
3 | You can provide additional custom headers for your requests:
4 |
5 | ```js
6 | const clientOptions = {
7 | customHeaders: {
8 | 'X-Custom-Header': 'CustomValue'
9 | }
10 | };
11 | ```
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/custom-logging.md:
--------------------------------------------------------------------------------
1 | # Custom Logging
2 |
3 | `node-zendesk` provides an option to log to your own logger object. By default, it uses its own `ConsoleLogger`. To use a custom logger:
4 |
5 | ```js
6 | const clientOptions = {
7 | username: 'your_username',
8 | token: 'your_token',
9 | subdomain: 'your_subdomain',
10 | logger: yourCustomLogger,
11 | debug: true
12 | };
13 | const client = zendesk.createClient(clientOptions);
14 | ```
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/custom-transport.md:
--------------------------------------------------------------------------------
1 | # Custom Transport Configuration
2 |
3 | If you prefer not to use the default `cross-fetch`, you can configure a custom transport. Here's an example using `axios`:
4 |
5 | ```js
6 | const transportConfigUsingAxios = {
7 | async transportFn(uri, options) {
8 | // Convert the options to be compatible with axios
9 | const requestOptions = {
10 | ...options,
11 | url: uri,
12 | method: options.method || 'GET',
13 | data: options.body,
14 | };
15 |
16 | try {
17 | const response = await axios(requestOptions);
18 | return response;
19 | } catch (error) {
20 | if (error.response) {
21 | return error.response;
22 | }
23 | throw error;
24 | }
25 | },
26 |
27 | responseAdapter(response) {
28 | return {
29 | json: () => Promise.resolve(response.data),
30 | status: response.status,
31 | headers: {
32 | get: (headerName) => response.headers[headerName.toLowerCase()],
33 | },
34 | statusText: response.statusText,
35 | };
36 | },
37 | };
38 |
39 | const setupClient = (config) => {
40 | return zd.createClient({
41 | username: ZENDESK_USERNAME,
42 | subdomain: ZENDESK_SUBDOMAIN,
43 | token: ZENDESK_TOKEN,
44 | transportConfig: transportConfigUsingAxios,
45 | ...config,
46 | });
47 | };
48 |
49 | async function foo() {
50 | try {
51 | const client = setupClient({debug: false});
52 | const result = await client.users.list();
53 | console.dir(result);
54 | } catch (error) {
55 | console.error(`Failed: ${error.message}`);
56 | }
57 | }
58 |
59 | foo();
60 | ```
61 |
62 | This example demonstrates how to set up a client using `axios` as the transport mechanism instead of the default `cross-fetch`.
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/debugging.md:
--------------------------------------------------------------------------------
1 | # Debug Logging
2 |
3 | Enable or disable debug logging using the `debug` property:
4 |
5 | ```js
6 | const clientOptions = {
7 | debug: true
8 | };
9 | ```
10 |
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/endpoint-override.md:
--------------------------------------------------------------------------------
1 | # Endpoint URI Override
2 |
3 | If you have a middleware service or a proxy in front of the Zendesk API, you can override the default `endpointUri`. This can be useful for custom routing or handling of requests. Note that using this override will disable the `subdomain` option.
4 |
5 | ## Throttling
6 |
7 | Enable request throttling by setting the `throttle` flag:
8 |
9 | ```js
10 | const clientOptions = {
11 | throttle: true
12 | };
13 | ```
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | order:5
3 | ---
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/manage-apis.md:
--------------------------------------------------------------------------------
1 | # API Types
2 |
3 | `node-zendesk` supports different types of Zendesk APIs. By default, it uses the 'core' API. If you want to access the helpdesk API, you need to call it explicitly:
4 |
5 | ```js
6 | client.helpdesk.categories.list();
7 | ```
8 |
9 | Currently, there are only `helpdesk`, `services`, and `voice` and you can use them all by including the upon client instantiation as follows:
10 |
11 | ```js
12 | const clientOptions = {
13 | username: 'your_username',
14 | token: 'your_token',
15 | subdomain: 'your_subdomain',
16 | apiType: ['core', 'helpdesk', 'services', 'voice'],
17 | };
18 | const client = zendesk.createClient(clientOptions);
19 | ```
20 |
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/pagination.md:
--------------------------------------------------------------------------------
1 | # Pagination
2 |
3 | `node-zendesk` optimizes pagination by default, ensuring efficient retrieval of large datasets. However, if you wish to override the default pagination mechanism, you can do so during client instantiation:
4 |
5 | ```js
6 | const clientOptions = {
7 | username: 'your_username',
8 | token: 'your_token',
9 | subdomain: 'your_subdomain',
10 | query: { page: { size: 1 } }
11 | };
12 | const client = zendesk.createClient(clientOptions);
13 | ```
14 |
15 | ::: danger **Warning**
16 | Overriding the default pagination mechanism is not recommended. Additionally, cursor-based pagination in the Zendesk API does not support more than 100 items for most cursor-based endpoints.
17 | :::
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/sideload.md:
--------------------------------------------------------------------------------
1 | # Side-Loading
2 |
3 | Side-loading allows you to retrieve related records along with the primary records you're querying. To set side-loading, use the `setSideLoad` method:
4 |
5 | ```js
6 | client.users.setSideLoad(['group', 'role']);
7 | ```
--------------------------------------------------------------------------------
/docs/guide/Guide/Advanced/throttling.md:
--------------------------------------------------------------------------------
1 | # Throttling
2 |
3 | Enable request throttling by setting the `throttle` flag:
4 |
5 | ```js
6 | const clientOptions = {
7 | throttle: true
8 | };
--------------------------------------------------------------------------------
/docs/guide/Guide/authentication.md:
--------------------------------------------------------------------------------
1 | ---
2 | order: 2
3 | ---
4 |
5 | # Authentication
6 |
7 | To interact with the Zendesk API using `node-zendesk`, you'll need to authenticate your requests. This section will guide you through the different authentication methods supported by the library.
8 |
9 | ## Basic Authentication
10 |
11 | Using a combination of your username, token, and subdomain, you can quickly set up basic authentication:
12 |
13 | ::: code-group
14 |
15 | ```js
16 | var zendesk = require('node-zendesk');
17 |
18 | var client = zendesk.createClient({
19 | username: 'your_username',
20 | token: 'your_token',
21 | subdomain: 'your_subdomain'
22 | });
23 | ```
24 |
25 | ```ts
26 | import {createClient} from 'node-zendesk'
27 |
28 | var client = createClient({
29 | username: 'your_username',
30 | token: 'your_token',
31 | subdomain: 'your_subdomain'
32 | });
33 | ```
34 | :::
35 |
36 | ## OAuth Authentication
37 |
38 | If you prefer to use an OAuth token for authentication, set the oauth key to true when creating the client. You can learn more about obtaining OAuth tokens from Zendesk's developer site.
39 |
40 | ::: code-group
41 | ```js
42 | var zendesk = require('node-zendesk');
43 |
44 | var client = zendesk.createClient({
45 | token: 'your_oauth_token',
46 | oauth: true
47 | });
48 | ```
49 |
50 | ```ts
51 | import {createClient} from 'node-zendesk'
52 |
53 | var client = zendesk.createClient({
54 | token: 'your_oauth_token',
55 | oauth: true
56 | });
57 | ```
58 | :::
59 |
60 | ## Impersonation
61 |
62 | To make API requests on behalf of end users, you can use the impersonation feature. Ensure you've granted the impersonate scope and then pass the end-user's email when creating the client:
63 |
64 | ::: code-group
65 | ```js
66 | var zendesk = require('node-zendesk');
67 |
68 | var client = createClient({
69 | username: 'your_username',
70 | token: 'your_oauth_token',
71 | subdomain: 'your_subdomain',
72 | oauth: true,
73 | asUser: 'end-user@example.com'
74 | });
75 | ```
76 |
77 | ```ts
78 | import {createClient} from 'node-zendesk'
79 |
80 | var client = createClient({
81 | username: 'your_username',
82 | token: 'your_oauth_token',
83 | subdomain: 'your_subdomain',
84 | oauth: true,
85 | asUser: 'end-user@example.com'
86 | });
87 | ```
88 | :::
89 |
90 | With authentication set up, you're ready to start making requests to the Zendesk API. In the following sections, we'll delve into more advanced features and usage patterns of node-zendesk.
--------------------------------------------------------------------------------
/docs/guide/Guide/final.md:
--------------------------------------------------------------------------------
1 | ---
2 | order: 4
3 | ---
4 |
5 |
8 |
9 | # Facing Issues or Want to Contribute?
10 |
11 | 🌟 **Love `node-zendesk`?** Please consider [starring the project on GitHub](https://github.com/blakmatrix/node-zendesk)!
12 |
13 | Star
14 |
15 | It's a quick way to show your appreciation and helps us reach more users.
16 |
17 | `node-zendesk` is a community-driven project, and we highly value your feedback and contributions. If you encounter any challenges, have suggestions for improvements, or want to be a part of its growth, here's how you can participate:
18 |
19 | ## Reporting Issues
20 |
21 | If you stumble upon a bug, experience unexpected behavior, or have questions about `node-zendesk`, please [open an issue](https://github.com/blakmatrix/node-zendesk/issues) on our GitHub repository. When reporting an issue:
22 |
23 | - **Be Specific**: Clearly describe the problem you're encountering. Detail the steps to reproduce it, if possible.
24 | - **Include Version Info**: Specify the version of `node-zendesk` you're using, and any other pertinent details about your environment.
25 | - **Screenshots & Logs**: Attach screenshots or logs when relevant to provide a clearer picture of the issue.
26 |
27 | ## Contributing via Pull Requests
28 |
29 | Have you enhanced `node-zendesk` or fixed an existing bug? We'd be thrilled to review your contributions! Here's how you can submit a pull request:
30 |
31 | - Fork the [`node-zendesk` repository](https://github.com/blakmatrix/node-zendesk).
32 | - Create a new branch dedicated to your modifications.
33 | - Commit your changes with a comprehensive description of your updates.
34 | - Initiate a pull request against the main branch of the `node-zendesk` repository.
35 |
36 | Before finalizing your submission, ensure your code aligns with our coding standards and has undergone testing.
37 |
38 | ## Support the Project
39 |
40 | Your feedback and contributions significantly influence the development and success of `node-zendesk`. If you find this project beneficial and wish to offer further support, consider [sponsoring](https://github.com/blakmatrix/node-zendesk/sponsors) or starring our repository.
41 |
42 | We're grateful for your involvement in our community and your efforts to enhance `node-zendesk` for all users!
43 |
--------------------------------------------------------------------------------
/docs/guide/Guide/installation.md:
--------------------------------------------------------------------------------
1 | ---
2 | order: 1
3 | ---
4 |
5 | # Installation
6 |
7 | Setting up `node-zendesk` is straightforward. Follow the steps below to get it up and running in your project.
8 |
9 | ## Installing via npm
10 |
11 | To install `node-zendesk`, use the npm command:
12 |
13 | ```shell
14 | npm install --save node-zendesk
15 | ```
16 | This command installs `node-zendesk` as a dependency in your project, making it available for you to import and use.
17 |
18 | ## TypeScript Support
19 |
20 | Starting from version `v5.0.0`, `node-zendesk` automatically generates TypeScript types. This means you no longer need to seek out third-party type definitions from DefinitelyTyped or elsewhere. Just install the library, and you'll have access to accurate and up-to-date TypeScript definitions out of the box.
21 |
22 | In the next sections, we'll guide you through basic usage and authentication to get you started with interacting with the Zendesk API.
--------------------------------------------------------------------------------
/docs/guide/index.md:
--------------------------------------------------------------------------------
1 | # Getting Started with `node-zendesk`
2 |
3 | Welcome to the `node-zendesk` guide! This guide is designed to help you seamlessly integrate `node-zendesk` into your projects, ensuring efficient interactions with the Zendesk API using Node.js.
4 |
5 | ## Prerequisites
6 |
7 | - A JavaScript/TypeScript project setup.
8 | - Familiarity with asynchronous programming in JavaScript.
9 |
10 | In the subsequent sections, we'll guide you through the installation process, basic usage, advanced features, and more. Dive in to get started!
11 |
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | # https://vitepress.dev/reference/default-theme-home-page
3 | layout: home
4 |
5 | hero:
6 | name: "node-zendesk"
7 | text: "A Zendesk API client wrapper"
8 | tagline: Power Up Zendesk: A robust wrapper for seamless API interactions.
9 | actions:
10 | - theme: brand
11 | text: Guide
12 | link: /guide/
13 | - theme: alt
14 | text: API Examples
15 | link: /code/README
16 | image:
17 | src: /Node_Zendesk_logo.svg
18 | alt: node-zendesk logo
19 |
20 | features:
21 | - icon: 🌍
22 | title: Seamless Integration with Zendesk
23 | details: Elevate your apps with node-zendesk
. Seamlessly and efficiently connect your applications with Zendesk's vast suite of customer service and engagement products. Our library is purpose-built to tap into Zendesk's APIs without a hiccup.
24 | link: "https://developer.zendesk.com/rest_api/docs/core/introduction"
25 | linkText: "Zendesk's documentation"
26 | - icon: ⚡️
27 | title: Modern and Lightweight
28 | details: Built with the modern developer in mind, node-zendesk
is lightweight and optimized for performance. Experience rapid setup and minimal overhead, with top-notch support for both JavaScript and TypeScript.
29 | - icon:
30 | title: "Extensive Linting with xo
"
31 | details: "No more bikeshedding about code styles. node-zendesk
adopts the xo
package, ensuring code is always in its best shape. Benefit from built-in linting that covers almost all coding scenarios and integrates seamlessly with many editors."
32 | link: https://github.com/xojs/xo/tree/main#editor-plugins
33 | linkText: "Learn about xo's editor plugins"
34 | - icon: 🤝
35 | title: "Active Community and Transparent Development"
36 | details: "With node-zendesk
, you're never coding alone. Join an active community of developers, get swift answers to queries, and enjoy the benefits of open and transparent development. We value every contributor, and our maintenance is a labor of love."
37 | link: https://github.com/blakmatrix/node-zendesk/blob/master/CONTRIBUTING.md
38 | linkText: "Contribute to node-zendesk"
39 |
40 |
41 | ---
42 |
--------------------------------------------------------------------------------
/docs/old/api-coverage.md:
--------------------------------------------------------------------------------
1 | API Coverage Doc
2 | =====================
3 |
4 | This document specifies the endpoints that are not yet included in the node-zendesk library. Its contents will change as Zendesk updates its documentation and as PRs are merged.
5 |
6 | ## Core API
7 |
8 | ```
9 | PUT /api/v2/dynamic_content/items/{id}/variants/update_many.json
10 | ```
11 |
12 | ## Help Center API
13 |
14 |
15 |
16 | ## Zopim API
17 |
18 | Client authentication and all APIs need some love.
19 |
20 | ## Reseller API
21 |
22 | All APIs need some love. However, the Reseller API is only accessible to Zendesk partners and resellers. Contact channel@zendesk.com if you're interested in gaining access.
23 |
--------------------------------------------------------------------------------
/docs/old/future-features.md:
--------------------------------------------------------------------------------
1 | ### Future Features
2 |
3 | * provide option to disable auto-paging https://github.com/blakmatrix/node-zendesk/issues/46
4 | * better memory managment for users that request all tickets ever https://github.com/blakmatrix/node-zendesk/issues/93
5 | * query sorting https://github.com/blakmatrix/node-zendesk/issues/111
6 | * rate-limiting zendesk API confusion https://github.com/blakmatrix/node-zendesk/issues/126
7 | * expose `.client.request` https://github.com/blakmatrix/node-zendesk/issues/129
8 | * Missing locale support for help-center category list https://github.com/blakmatrix/node-zendesk/issues/149
9 | * Implement `tickets.createMany()` https://github.com/blakmatrix/node-zendesk/issues/153
10 | * Promise support? https://github.com/blakmatrix/node-zendesk/issues/156
11 | * Create user with default password https://github.com/blakmatrix/node-zendesk/issues/157
12 | * Support URL source for file upload
--------------------------------------------------------------------------------
/docs/old/meetings/2015-05-09.md:
--------------------------------------------------------------------------------
1 | # node-zendesk WG 2015-05-09
2 |
3 | ### Present
4 | - Farin
5 | - Xiaochen
6 | - Eriks
7 |
8 | ### Discussion Notes
9 | - Intro of working group
10 | - Divvy up responsibilities
11 | - Eriks: WG Doc and API Coverage Roadmap
12 | - Xiaochen: Assess use of nconf (as it relates to [issue #80](https://github.com/blakmatrix/node-zendesk/issues/80))
13 | - Farin: Assess Core API coverage
14 |
15 | ### Next Meeting
16 | ~ May 23
17 |
--------------------------------------------------------------------------------
/examples/activities-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.activitystream.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result));
18 | console.log('Total activities: ' + result.length);
19 | });
20 |
--------------------------------------------------------------------------------
/examples/automations-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.automations.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result));
18 | console.log('Total automations: ' + result.length);
19 | });
20 |
--------------------------------------------------------------------------------
/examples/busey.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blakmatrix/node-zendesk/514199080d654bfbb5a6638fdee48e7a9a595809/examples/busey.gif
--------------------------------------------------------------------------------
/examples/check-auth-promise.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.users
12 | .auth()
13 | .then(function (response) {
14 | const result = response;
15 | console.dir(result.verified);
16 | })
17 | .catch(function (error) {
18 | console.log(error);
19 | });
20 |
--------------------------------------------------------------------------------
/examples/check-auth-token.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.users.auth(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result.verified, null, 2, true));
18 | });
19 |
--------------------------------------------------------------------------------
/examples/check-auth.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.users.auth(function (error, request, result) {
12 | if (error) {
13 | // Console.log(err);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result.verified, null, 2, true));
18 | });
19 |
--------------------------------------------------------------------------------
/examples/check-oauth-token.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const zd = require('../src/index.js');
5 |
6 | dotenv.config();
7 |
8 | const setupClient = () => {
9 | return zd.createClient({
10 | token: process.env.ZENDESK_OAUTH_ACCESS_TOKEN,
11 | subdomain: process.env.ZENDESK_SUBDOMAIN,
12 | useOAuth: true,
13 | });
14 | };
15 |
16 | const client = setupClient();
17 |
18 | /**
19 | * Checks the OAuth authentication for the Zendesk client and logs the verification status.
20 | * @returns {Promise} A promise that resolves when the check is complete.
21 | */
22 | async function checkOAuth() {
23 | try {
24 | const {result: user} = await client.users.auth();
25 | console.log(user.verified);
26 | } catch (error) {
27 | console.error(`Failed to check OAuth: ${error.message}`);
28 | }
29 | }
30 |
31 | checkOAuth();
32 |
--------------------------------------------------------------------------------
/examples/create-oauth-token.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const zd = require('../src/index.js');
5 |
6 | // Load environment variables from .env file
7 | dotenv.config();
8 |
9 | /**
10 | * Set up and return a Zendesk client with the given configuration.
11 | * @param {object} config - Additional configuration for the Zendesk client.
12 | * @returns {object} Zendesk client instance.
13 | */
14 | const setupClient = (config) => {
15 | return zd.createClient({
16 | username: process.env.ZENDESK_USERNAME,
17 | subdomain: process.env.ZENDESK_SUBDOMAIN,
18 | token: process.env.ZENDESK_TOKEN,
19 | ...config,
20 | });
21 | };
22 |
23 | /**
24 | * Retrieves the numeric ID of an OAuth client based on its unique identifier.
25 | * @param {string} identifier - The unique identifier of the OAuth client.
26 | * @returns {Promise} The numeric ID of the OAuth client or null if not found.
27 | * @throws {Error} If there's an error in retrieving the OAuth client list.
28 | */
29 | async function getClientId(identifier) {
30 | try {
31 | const client = setupClient({debug: false});
32 | const result = await client.oauthclients.list();
33 | const oauthClient = result.find((c) => c.identifier === identifier);
34 | return oauthClient ? oauthClient.id : null;
35 | } catch (error) {
36 | console.error('Error retrieving OAuth client ID:', error.message);
37 | return null;
38 | }
39 | }
40 |
41 | /**
42 | * Creates a read-only OAuth token for accessing users and tickets.
43 | * This function first retrieves the OAuth client ID using its unique identifier,
44 | * and then uses this ID to create a token with the specified scopes.
45 | * @throws {Error} If the OAuth client ID is not found or if there's an error in creating the OAuth token.
46 | */
47 | async function createReadOnlyOAuthToken() {
48 | try {
49 | const oauthClientId = await getClientId(
50 | process.env.ZENDESK_OAUTH_CLIENT_UNIQUE_IDENTIFIER,
51 | );
52 | if (!oauthClientId) {
53 | throw new Error('OAuth client ID not found for the given identifier.');
54 | }
55 |
56 | const client = setupClient({debug: false});
57 |
58 | // Create an OAuth token with read-only access to users and tickets
59 | const {result} = await client.oauthtokens.create({
60 | token: {
61 | client_id: oauthClientId, // Numeric OAuth client ID
62 | scopes: ['users:read', 'tickets:read'], // Scopes for read-only access
63 | },
64 | });
65 |
66 | console.log('OAuth Token Created:', result);
67 | } catch (error) {
68 | console.error('Error creating OAuth token:', error.message);
69 | }
70 | }
71 |
72 | createReadOnlyOAuthToken();
73 |
--------------------------------------------------------------------------------
/examples/delete-many-organizations.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /* eslint-disable no-await-in-loop */
3 | const process = require('node:process');
4 | const dotenv = require('dotenv');
5 | const zd = require('../src/index.js');
6 |
7 | dotenv.config();
8 |
9 | const setupClient = (config) => {
10 | return zd.createClient({
11 | username: process.env.ZENDESK_USERNAME,
12 | subdomain: process.env.ZENDESK_SUBDOMAIN,
13 | token: process.env.ZENDESK_TOKEN,
14 | ...config,
15 | });
16 | };
17 |
18 | // Placeholder organization ID for development/testing.
19 | // IMPORTANT: Replace with a valid organization ID before running in production.
20 |
21 | /**
22 | *
23 | */
24 | async function organizationsDelete() {
25 | let collector = [];
26 | try {
27 | const client = setupClient({debug: false});
28 | const allOrgs = await client.organizations.list();
29 | for (const element of allOrgs) {
30 | if (element.name.startsWith('testOrganization')) {
31 | collector.push(element);
32 | }
33 |
34 | if (collector.length >= 30) {
35 | const ids = collector.map(function (i) {
36 | return i.id;
37 | });
38 | await client.organizations.bulkDelete(ids);
39 | collector = [];
40 | }
41 | }
42 | } catch (error) {
43 | console.error(`Failed to delete organization: ${error.message}`);
44 | }
45 | }
46 |
47 | organizationsDelete();
48 |
--------------------------------------------------------------------------------
/examples/endpoint.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const zd = require('../src/index.js');
5 |
6 | dotenv.config();
7 |
8 | const setupClient = (config) => {
9 | return zd.createClient({
10 | username: process.env.ZENDESK_USERNAME,
11 | endpointUri: process.env.ZENDESK_ENDPOINT_URI,
12 | token: process.env.ZENDESK_TOKEN,
13 | ...config,
14 | });
15 | };
16 |
17 | /**
18 | *
19 | */
20 | async function usersList() {
21 | try {
22 | const client = setupClient({debug: false});
23 | const result = await client.users.list();
24 | console.log(
25 | JSON.stringify(
26 | result.map(function (user) {
27 | return user.name;
28 | }),
29 | null,
30 | 2,
31 | true,
32 | ),
33 | ); // Gets the first page
34 | console.log('Total Users: ' + result.length);
35 | } catch (error) {
36 | console.error(`Failed to get list of users: ${error.message}`);
37 | }
38 | }
39 |
40 | usersList();
41 |
--------------------------------------------------------------------------------
/examples/example-config.js:
--------------------------------------------------------------------------------
1 | exports.auth = {
2 | username: 'example@zendesk.com',
3 | token: '',
4 | remoteUri: 'https://example.zendesk.com/api/v2',
5 | };
6 |
--------------------------------------------------------------------------------
/examples/groupmemberships-list-group.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | /**
12 | *
13 | */
14 | async function listGroupMemberships() {
15 | try {
16 | const groups = await client.groups.list();
17 | const group = groups[0];
18 |
19 | if (!group) {
20 | console.log('No groups found.');
21 | return;
22 | }
23 |
24 | const memberships = await client.groupmemberships.listByGroup(group.id);
25 | console.log(JSON.stringify(memberships));
26 | } catch (error) {
27 | console.error('Error fetching group memberships:', error);
28 | }
29 | }
30 |
31 | listGroupMemberships();
32 |
--------------------------------------------------------------------------------
/examples/groupmemberships-list-user.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | /**
12 | *
13 | */
14 | async function listUserMemberships() {
15 | try {
16 | const users = await client.users.list();
17 | const user = users[0];
18 |
19 | if (!user) {
20 | console.log('No users found.');
21 | return;
22 | }
23 |
24 | const memberships = await client.groupmemberships.listByUser(user.id);
25 | console.log(JSON.stringify(memberships));
26 | } catch (error) {
27 | console.error('Error fetching user memberships:', error);
28 | }
29 | }
30 |
31 | listUserMemberships();
32 |
--------------------------------------------------------------------------------
/examples/groupmemberships-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.groupmemberships.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result));
18 | console.log('Total Memberships: ' + result.length);
19 | });
20 |
--------------------------------------------------------------------------------
/examples/groups-list-assignable.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.groups.assignable(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(
18 | JSON.stringify(
19 | result.map(function (grp) {
20 | return grp.name;
21 | }),
22 | null,
23 | 2,
24 | true,
25 | ),
26 | ); // Gets the first page
27 | console.log('Total Groups: ' + result.length);
28 | });
29 |
--------------------------------------------------------------------------------
/examples/groups-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.groups.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(
18 | JSON.stringify(
19 | result.map(function (grp) {
20 | return grp.name;
21 | }),
22 | null,
23 | 2,
24 | true,
25 | ),
26 | ); // Gets the first page
27 | console.log('Total Groups: ' + result.length);
28 | });
29 |
--------------------------------------------------------------------------------
/examples/macros-active-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.macros.listByParams(['?active=true'], function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result));
18 | console.log('Total Groups: ' + result.length);
19 | });
20 |
--------------------------------------------------------------------------------
/examples/optional-axios-transport.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const axios = require('axios');
5 | const zd = require('../src/index.js');
6 |
7 | dotenv.config();
8 |
9 | const transportConfigUsingAxios = {
10 | async transportFn(uri, options) {
11 | // Convert the options to be compatible with axios
12 | const requestOptions = {
13 | ...options,
14 | url: uri,
15 | method: options.method || 'GET', // Axios uses 'method', not just 'GET' or 'POST' as direct options
16 | data: options.body, // Axios uses 'data' instead of 'body'
17 | };
18 |
19 | try {
20 | const response = await axios(requestOptions);
21 | return response;
22 | } catch (error) {
23 | // If axios throws an error, it usually encapsulates the actual server response within error.response.
24 | // This is to ensure that even for error HTTP statuses, the response can be adapted consistently.
25 | if (error.response) {
26 | return error.response;
27 | }
28 |
29 | throw error; // If there's no error.response, then throw the error as is.
30 | }
31 | },
32 |
33 | responseAdapter(response) {
34 | return {
35 | json: () => Promise.resolve(response.data),
36 | status: response.status,
37 | headers: {
38 | get: (headerName) => response.headers[headerName.toLowerCase()],
39 | },
40 | statusText: response.statusText,
41 | };
42 | },
43 | };
44 |
45 | const setupClient = (config) => {
46 | return zd.createClient({
47 | username: process.env.ZENDESK_USERNAME,
48 | subdomain: process.env.ZENDESK_SUBDOMAIN,
49 | token: process.env.ZENDESK_TOKEN,
50 | transportConfig: transportConfigUsingAxios,
51 | ...config,
52 | });
53 | };
54 |
55 | /**
56 | *
57 | */
58 | async function foo() {
59 | try {
60 | const client = setupClient({debug: false});
61 | const result = await client.users.list();
62 |
63 | console.dir(result);
64 | } catch (error) {
65 | console.error(`Failed: ${error.message}`);
66 | }
67 | }
68 |
69 | foo();
70 |
--------------------------------------------------------------------------------
/examples/optional-deprecated-request-transport.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const request = require('request');
5 | const zd = require('../src/index.js');
6 |
7 | dotenv.config();
8 |
9 | const transportConfigUsingRequest = {
10 | transportFn(uri, options) {
11 | // Convert the options to be compatible with the request library
12 | const requestOptions = {
13 | ...options,
14 | uri,
15 | headers: options.headers,
16 | };
17 |
18 | return new Promise((resolve, reject) => {
19 | request(requestOptions, (error, response, body) => {
20 | if (error) {
21 | reject(error);
22 | } else {
23 | // Include the body in the response object for the adapter to handle
24 | response.body = body;
25 | resolve(response);
26 | }
27 | });
28 | });
29 | },
30 |
31 | responseAdapter(response) {
32 | return {
33 | json() {
34 | try {
35 | return Promise.resolve(JSON.parse(response.body));
36 | } catch (error) {
37 | return Promise.reject(
38 | new Error(`Failed to parse JSON: ${error.message}`),
39 | );
40 | }
41 | },
42 | status: response.statusCode,
43 | headers: {
44 | get: (headerName) => response.headers[headerName.toLowerCase()],
45 | },
46 | statusText: response.statusMessage,
47 | };
48 | },
49 | };
50 |
51 | const setupClient = (config) => {
52 | return zd.createClient({
53 | username: process.env.ZENDESK_USERNAME,
54 | subdomain: process.env.ZENDESK_SUBDOMAIN,
55 | token: process.env.ZENDESK_TOKEN,
56 | transportConfig: transportConfigUsingRequest,
57 | ...config,
58 | });
59 | };
60 |
61 | /**
62 | *
63 | */
64 | async function foo() {
65 | try {
66 | const client = setupClient({debug: false});
67 | const result = await client.users.list();
68 |
69 | console.dir(result);
70 | } catch (error) {
71 | console.error(`Failed: ${error.message}`);
72 | }
73 | }
74 |
75 | foo();
76 |
--------------------------------------------------------------------------------
/examples/organization-fields-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.organizationfields.list(function (error, statusList, body) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(body, null, 2, true));
18 | });
19 |
--------------------------------------------------------------------------------
/examples/organization-memberships-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.organizationmemberships.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result)); // Gets the first page
18 | console.log('Total memberships: ' + result.length);
19 | });
20 |
--------------------------------------------------------------------------------
/examples/organization-upsert.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const zd = require('../lib/client');
4 | const exampleConfig = require('./exampleConfig');
5 |
6 | const client = zd.createClient({
7 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
8 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
9 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
10 | });
11 |
12 | const organization = {
13 | organization: {
14 | id: 35_436,
15 | name: 'My Organization',
16 | },
17 | };
18 |
19 | client.organizations.upsert(organization, function (error, request, result) {
20 | if (error) return handleError(error);
21 | console.log(JSON.stringify(result, null, 2, true));
22 | });
23 |
24 | /**
25 | * Handles errors by logging them and exiting the process.
26 | * @param {Error} error - The error object to be handled.
27 | */
28 | function handleError(error) {
29 | console.log(error);
30 | process.exit(-1);
31 | }
32 |
--------------------------------------------------------------------------------
/examples/organizations-delete-bulk.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /* eslint-disable no-await-in-loop */
3 |
4 | const process = require('node:process');
5 | const dotenv = require('dotenv');
6 | const zd = require('../src/index.js');
7 |
8 | dotenv.config();
9 |
10 | /**
11 | * Initializes and returns a Zendesk client.
12 | * @returns {object} Zendesk client instance.
13 | */
14 | function initializeZendeskClient() {
15 | return zd.createClient({
16 | username: process.env.ZENDESK_USERNAME,
17 | subdomain: process.env.ZENDESK_SUBDOMAIN,
18 | token: process.env.ZENDESK_TOKEN,
19 | debug: false,
20 | });
21 | }
22 |
23 | /**
24 | * Filters and returns organization IDs that start with "test" or "Test".
25 | * @param {Array} organizations - List of organizations.
26 | * @returns {Array} List of organization IDs.
27 | */
28 | function getTestOrganizationIds(organizations) {
29 | return organizations
30 | .filter((org) => org.name.startsWith('test') || org.name.startsWith('Test'))
31 | .map((org) => org.id);
32 | }
33 |
34 | /**
35 | * Splits an array into chunks of a specified size.
36 | * @param {Array} array - The array to split.
37 | * @param {number} chunkSize - The size of each chunk.
38 | * @returns {Array} An array of chunks.
39 | */
40 | function chunkArray(array, chunkSize) {
41 | const chunks = [];
42 | for (let i = 0; i < array.length; i += chunkSize) {
43 | chunks.push(array.slice(i, i + chunkSize));
44 | }
45 |
46 | return chunks;
47 | }
48 |
49 | /**
50 | * Monitors the completion of a job.
51 | * @param {object} client - The Zendesk client instance.
52 | * @param {string} jobID - The ID of the job to monitor.
53 | * @returns {Promise} Resolves when the job is complete.
54 | */
55 | async function monitorJobCompletion(client, jobID) {
56 | try {
57 | await client.jobstatuses.watch(jobID, 1000, 30);
58 | } catch (error) {
59 | console.error('Error watching job status:', error);
60 | throw error;
61 | }
62 | }
63 |
64 | /**
65 | * Performs a bulk deletion of test organizations.
66 | * @returns {Promise} Resolves when all organizations are deleted.
67 | */
68 | async function bulkDeleteTestOrganizations() {
69 | const client = initializeZendeskClient();
70 |
71 | try {
72 | const organizations = await client.organizations.list();
73 | const orgIdsToDelete = getTestOrganizationIds(organizations);
74 | const chunks = chunkArray(orgIdsToDelete, 30);
75 |
76 | for (const chunk of chunks) {
77 | const {result} = await client.organizations.bulkDelete(chunk);
78 | const {job_status} = result;
79 |
80 | if (job_status && job_status.id) {
81 | await monitorJobCompletion(client, job_status.id);
82 | }
83 |
84 | if (job_status && job_status.status) {
85 | console.log(
86 | `Successfully deleted chunk of ${chunk.length} organizations.`,
87 | );
88 | } else {
89 | console.dir(job_status);
90 | }
91 | }
92 |
93 | console.log('All organizations deleted successfully.');
94 | } catch (error) {
95 | if (error.message.includes('TooManyJobs')) {
96 | console.error(
97 | 'Too many jobs are currently queued or running. Try again later.',
98 | );
99 | } else {
100 | console.error(
101 | `Failed to bulk delete test organizations: ${error.message}`,
102 | );
103 | }
104 | }
105 | }
106 |
107 | bulkDeleteTestOrganizations();
108 |
--------------------------------------------------------------------------------
/examples/organizations-delete.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const zd = require('../src/index.js');
5 |
6 | dotenv.config();
7 |
8 | const setupClient = (config) => {
9 | return zd.createClient({
10 | username: process.env.ZENDESK_USERNAME,
11 | subdomain: process.env.ZENDESK_SUBDOMAIN,
12 | token: process.env.ZENDESK_TOKEN,
13 | ...config,
14 | });
15 | };
16 |
17 | // Placeholder organization ID for development/testing.
18 | // IMPORTANT: Replace with a valid organization ID before running in production.
19 | const organizationID = 1_234_567_890;
20 |
21 | /**
22 | *
23 | */
24 | async function organizationsDelete() {
25 | try {
26 | const client = setupClient({debug: false});
27 | const {result} = await client.organizations.delete(organizationID);
28 | if (result.message === 'No Content') {
29 | console.log('Organization deleted');
30 | } else {
31 | console.dir(result);
32 | }
33 | } catch (error) {
34 | console.error(`Failed to delete organization: ${error.message}`);
35 | }
36 | }
37 |
38 | organizationsDelete();
39 |
--------------------------------------------------------------------------------
/examples/organizations-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.organizations.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(
18 | JSON.stringify(
19 | result.map(function (org) {
20 | return org.name;
21 | }),
22 | null,
23 | 2,
24 | true,
25 | ),
26 | ); // Gets the first page
27 | console.log('Total Orgs: ' + result.length);
28 | });
29 |
--------------------------------------------------------------------------------
/examples/search-query.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | const query = 'status {
22 | try {
23 | const result = await client.tickets.create(ticket);
24 | console.log(JSON.stringify(result, null, 2, true));
25 | } catch (error) {
26 | handleError(error);
27 | }
28 | })();
29 |
30 | /**
31 | * Handles errors by logging them and exiting the process.
32 | * @param {Error} error - The error object to be handled.
33 | */
34 | function handleError(error) {
35 | console.log(error);
36 | process.exit(-1);
37 | }
38 |
--------------------------------------------------------------------------------
/examples/ticket-create.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const zd = require('../lib/client');
4 | const exampleConfig = require('./exampleConfig');
5 |
6 | const client = zd.createClient({
7 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
8 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
9 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
10 | });
11 |
12 | const ticket = {
13 | ticket: {
14 | subject: 'My printer is on fire!',
15 | comment: {
16 | body: 'The smoke is very colorful.',
17 | },
18 | },
19 | };
20 |
21 | client.tickets.create(ticket, function (error, request, result) {
22 | if (error) return handleError(error);
23 | console.log(JSON.stringify(result, null, 2, true));
24 | });
25 |
26 | /**
27 | * Handles errors by logging them and exiting the process.
28 | * @param {Error} error - The error object to be handled.
29 | */
30 | function handleError(error) {
31 | console.log(error);
32 | process.exit(-1);
33 | }
34 |
--------------------------------------------------------------------------------
/examples/ticket-delete.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const zd = require('../lib/client');
4 | const exampleConfig = require('./exampleConfig');
5 |
6 | const client = zd.createClient({
7 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
8 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
9 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
10 | });
11 |
12 | const ticketId = 12_345;
13 | client.tickets.delete(ticketId, function (error) {
14 | if (error) return handleError(error);
15 | });
16 |
17 | /**
18 | * Handles errors by logging them and exiting the process.
19 | * @param {Error} error - The error object to be handled.
20 | */
21 | function handleError(error) {
22 | console.log(error);
23 | process.exit(-1);
24 | }
25 |
--------------------------------------------------------------------------------
/examples/ticket-list-observer.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | const observer = {
12 | error: console.error,
13 | // eslint-disable-next-line max-params
14 | next(status, body, response, result, nextPage) {
15 | console.log(JSON.stringify(body, null, 2, true));
16 | console.log('Next page:', nextPage);
17 | },
18 | complete(statusList, body /* , responseList, resultList */) {
19 | console.log('Pagination complete.');
20 | console.log(body); // Will display all tickets
21 | },
22 | };
23 |
24 | client.tickets.list(observer);
25 |
--------------------------------------------------------------------------------
/examples/ticket-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.tickets.list(
12 | function (error, statusList, body /* , responseList, resultList */) {
13 | if (error) {
14 | console.log(error);
15 | return;
16 | }
17 |
18 | console.log(JSON.stringify(body, null, 2, true)); // Will display all tickets
19 | },
20 | );
21 |
--------------------------------------------------------------------------------
/examples/ticketaudits-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | /**
12 | *
13 | */
14 | async function listTicketAudits() {
15 | try {
16 | const tickets = await client.tickets.list();
17 | const ticket = tickets[0];
18 |
19 | if (!ticket) {
20 | console.log('No tickets found.');
21 | return;
22 | }
23 |
24 | const audits = await client.ticketaudits.list(ticket.id);
25 | console.log(JSON.stringify(audits));
26 | } catch (error) {
27 | console.error('Error fetching ticket audits:', error);
28 | }
29 | }
30 |
31 | listTicketAudits();
32 |
--------------------------------------------------------------------------------
/examples/ticketmetric-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.ticketmetrics.listAll(
12 | function (error, statusList, body /* , responseList, resultList */) {
13 | if (error) {
14 | console.log(error);
15 | return;
16 | }
17 |
18 | console.log(JSON.stringify(body));
19 | },
20 | );
21 |
--------------------------------------------------------------------------------
/examples/triggers-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.triggers.list(
12 | function (error, statusList, body /* , responseList, resultList */) {
13 | if (error) {
14 | console.log(error);
15 | return;
16 | }
17 |
18 | console.log(JSON.stringify(body)); // Will display all triggers
19 | },
20 | );
21 |
--------------------------------------------------------------------------------
/examples/upload-attachment.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const path = require('node:path');
3 | const zd = require('../lib/client');
4 | const exampleConfig = require('./exampleConfig');
5 |
6 | const ATTACHMENT_PATH = path.resolve('./examples/busey.gif');
7 | const FILENAME = 'busey.gif';
8 |
9 | /**
10 | * Initializes and returns a Zendesk client.
11 | * @returns {object} Zendesk client instance.
12 | */
13 | function getZendeskConfig() {
14 | return {
15 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
16 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
17 | remoteUri:
18 | process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
19 | };
20 | }
21 |
22 | const client = zd.createClient(getZendeskConfig());
23 |
24 | /**
25 | * Uploads an attachment to Zendesk.
26 | * @param {string} filePath - The path to the file to be uploaded.
27 | * @param {string} fileName - The name of the file to be uploaded.
28 | */
29 | async function uploadAttachment(filePath, fileName) {
30 | try {
31 | const result = await client.attachments.upload(filePath, {
32 | filename: fileName,
33 | });
34 | console.log(JSON.stringify(result, null, 2));
35 | } catch (error) {
36 | console.error(`Failed to upload attachment: ${error.message}`);
37 | }
38 | }
39 |
40 | uploadAttachment(ATTACHMENT_PATH, FILENAME);
41 |
--------------------------------------------------------------------------------
/examples/user-create-many.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | const users = {
12 | users: [
13 | {
14 | name: 'Roger Wilco',
15 | email: 'roge@example.org',
16 | role: 'agent',
17 | },
18 | {
19 | name: 'Woger Rilco',
20 | email: 'woge@example.org',
21 | role: 'admin',
22 | },
23 | ],
24 | };
25 |
26 | client.users.createMany(users, function (error, request, result) {
27 | if (error) {
28 | console.log(error);
29 | return;
30 | }
31 |
32 | client.jobstatuses.watch(
33 | result.job_status.id,
34 | 500,
35 | 5,
36 | function (error_, request, result) {
37 | console.log(JSON.stringify(result, null, 2, true));
38 | },
39 | );
40 | });
41 |
--------------------------------------------------------------------------------
/examples/user-create-promise.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | const user = {
12 | user: {
13 | name: 'Foo Bar',
14 | email: 'FooBar@example.org',
15 | },
16 | };
17 |
18 | (async () => {
19 | try {
20 | const result = await client.users.create(user);
21 | console.log(JSON.stringify(result, null, 2, true));
22 | } catch (error) {
23 | console.log(error);
24 | }
25 | })();
26 |
--------------------------------------------------------------------------------
/examples/user-create.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | const user = {
12 | user: {
13 | name: 'Foo Bar',
14 | email: 'FooBar@example.org',
15 | },
16 | };
17 |
18 | client.users.create(user, function (error, request, result) {
19 | if (error) {
20 | console.log(error);
21 | return;
22 | }
23 |
24 | console.log(JSON.stringify(result, null, 2, true));
25 | });
26 |
--------------------------------------------------------------------------------
/examples/user-fields-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.userfields.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(
18 | JSON.stringify(
19 | result.map(function (userField) {
20 | return userField.key;
21 | }),
22 | null,
23 | 2,
24 | true,
25 | ),
26 | ); // Gets the first page
27 | console.log('Total User Fields: ' + result.length);
28 | });
29 |
--------------------------------------------------------------------------------
/examples/users-list.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const process = require('node:process');
3 | const dotenv = require('dotenv');
4 | const zd = require('../src/index.js');
5 |
6 | dotenv.config();
7 |
8 | const setupClient = (config) => {
9 | return zd.createClient({
10 | username: process.env.ZENDESK_USERNAME,
11 | subdomain: process.env.ZENDESK_SUBDOMAIN,
12 | token: process.env.ZENDESK_TOKEN,
13 | ...config,
14 | });
15 | };
16 |
17 | /**
18 | *
19 | */
20 | async function usersList() {
21 | try {
22 | const client = setupClient({debug: false});
23 | const result = await client.users.list();
24 | console.log(
25 | JSON.stringify(
26 | result.map(function (user) {
27 | return user.name;
28 | }),
29 | null,
30 | 2,
31 | true,
32 | ),
33 | ); // Gets the first page
34 | console.log('Total Users: ' + result.length);
35 | } catch (error) {
36 | console.error(`Failed to get list of users: ${error.message}`);
37 | }
38 | }
39 |
40 | usersList();
41 |
--------------------------------------------------------------------------------
/examples/users-listbygroup.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | /**
12 | *
13 | */
14 | async function listUsersByFirstGroup() {
15 | try {
16 | const groups = await client.groups.list();
17 | const firstGroup = groups[0];
18 |
19 | if (!firstGroup) {
20 | console.log('No groups found.');
21 | return;
22 | }
23 |
24 | const users = await client.users.listByGroup(firstGroup.id);
25 | console.log(users);
26 | } catch (error) {
27 | console.error(error);
28 | }
29 | }
30 |
31 | listUsersByFirstGroup();
32 |
--------------------------------------------------------------------------------
/examples/usertags-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | /**
12 | *
13 | */
14 | async function listTagsForFirstUser() {
15 | try {
16 | const users = await client.users.list();
17 | const firstUser = users[0];
18 |
19 | if (!firstUser) {
20 | console.log('No users found.');
21 | return;
22 | }
23 |
24 | const tags = await client.users.listTags(firstUser.id);
25 | console.log(tags);
26 | } catch (error) {
27 | console.error(error);
28 | }
29 | }
30 |
31 | listTagsForFirstUser();
32 |
--------------------------------------------------------------------------------
/examples/views-list.js:
--------------------------------------------------------------------------------
1 | const process = require('node:process');
2 | const zd = require('../lib/client');
3 | const exampleConfig = require('./exampleConfig');
4 |
5 | const client = zd.createClient({
6 | username: process.env.ZENDESK_TEST_USERNAME || exampleConfig.auth.username,
7 | token: process.env.ZENDESK_TEST_TOKEN || exampleConfig.auth.token,
8 | remoteUri: process.env.ZENDESK_TEST_REMOTEURI || exampleConfig.auth.remoteUri,
9 | });
10 |
11 | client.views.list(function (error, request, result) {
12 | if (error) {
13 | console.log(error);
14 | return;
15 | }
16 |
17 | console.log(JSON.stringify(result));
18 | console.log('Total Users: ' + result.length);
19 | });
20 |
--------------------------------------------------------------------------------
/src/clients/authorization-handler.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Handles the creation of authorization headers based on the provided configuration.
3 | * Supports both OAuth and Basic Authentication methods.
4 | */
5 | class AuthorizationHandler {
6 | /**
7 | * Creates a new instance of the AuthorizationHandler.
8 | * @param {Map} options - A Map object containing the necessary configuration options.
9 | */
10 | constructor(options) {
11 | this.options = options;
12 | }
13 |
14 | /**
15 | * Determines the authentication method and creates the appropriate authorization header.
16 | * @returns {string} The resulting authorization header string.
17 | */
18 | createAuthorizationHeader() {
19 | if (this.isOAuth()) {
20 | return this.createOAuthHeader();
21 | }
22 |
23 | return this.createBasicAuthHeader();
24 | }
25 |
26 | /**
27 | * Checks if OAuth should be used for authentication.
28 | * @returns {boolean} True if OAuth is the chosen method; false otherwise.
29 | */
30 | isOAuth() {
31 | return (
32 | this.options.get('useOAuth') === true ||
33 | this.options.get('oauth') === true
34 | );
35 | }
36 |
37 | /**
38 | * Creates the OAuth authorization header.
39 | * @returns {string} The OAuth authorization header.
40 | * @throws {Error} When the token is missing in the options.
41 | */
42 | createOAuthHeader() {
43 | const token = this.options.get('token');
44 |
45 | if (!token) {
46 | throw new Error('OAuth is enabled, but token is missing.');
47 | }
48 |
49 | return `Bearer ${token}`;
50 | }
51 |
52 | /**
53 | * Creates the Basic Authentication authorization header.
54 | * @returns {string} The Basic Authentication header.
55 | * @throws {Error} When username or password/token is missing in the options.
56 | */
57 | createBasicAuthHeader() {
58 | const username = this.options.get('username');
59 | const passwordOrToken = this.getPasswordOrToken();
60 |
61 | if (!username || !passwordOrToken) {
62 | throw new Error('Missing credentials for Basic Authentication.');
63 | }
64 |
65 | const encoded = this.encodeCredentials(`${username}${passwordOrToken}`);
66 | return `Basic ${encoded}`;
67 | }
68 |
69 | /**
70 | * Retrieves the password or token for Basic Authentication.
71 | * The method first checks for a password and if none is found, it fetches the token.
72 | * @returns {string} The password or token prefixed with the appropriate separator.
73 | */
74 | getPasswordOrToken() {
75 | const password = this.options.get('password');
76 | if (password) {
77 | return `:${password}`;
78 | }
79 |
80 | return `/token:${this.options.get('token')}`;
81 | }
82 |
83 | /**
84 | * Encodes the provided credentials using base64 encoding.
85 | * @param {string} credentials - The credentials to be encoded.
86 | * @returns {string} The base64 encoded string of the provided credentials.
87 | */
88 | encodeCredentials(credentials) {
89 | return require('node:buffer').Buffer.from(credentials).toString('base64');
90 | }
91 | }
92 |
93 | exports.AuthorizationHandler = AuthorizationHandler;
94 |
--------------------------------------------------------------------------------
/src/clients/core/accountsettings.js:
--------------------------------------------------------------------------------
1 | // AccountSettings.js: Client for the zendesk API.
2 |
3 | const {Client} = require('../client');
4 |
5 | /**
6 | * The AccountSettings class provides methods for interacting with account settings in the Zendesk JSON API.
7 | * {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/account_settings/ | See the Zendesk API documentation for more details}.
8 | */
9 | class AccountSettings extends Client {
10 | constructor(options) {
11 | super(options);
12 | this.jsonAPINames = ['settings'];
13 | }
14 |
15 | /**
16 | * Retrieves the account settings.
17 | * @returns {Promise<{response: object, result: object}>} A promise that resolves to the account settings.
18 | * {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/account_settings/#show-settings | See the Zendesk API documentation for more details}.
19 | * @example
20 | * const settings = await client.accountsettings.show();
21 | */
22 | async show() {
23 | return this.get(['account', 'settings']);
24 | }
25 |
26 | /**
27 | * Updates the account settings.
28 | * @param {object} settings - The settings to update.
29 | * @returns {Promise<{response: object, result: object}>} A promise that resolves to the updated account settings.
30 | * {@link https://developer.zendesk.com/api-reference/ticketing/account-configuration/account_settings/#update-account-settings | See the Zendesk API documentation for more details}.
31 | * @example
32 | * const settings = await client.accountsettings.update({ "settings": { "active_features": { "customer_satisfaction": false }}});
33 | */
34 | async update(settings) {
35 | return this.put(['account', 'settings'], settings);
36 | }
37 | }
38 |
39 | exports.AccountSettings = AccountSettings;
40 |
--------------------------------------------------------------------------------
/src/clients/core/activitystream.js:
--------------------------------------------------------------------------------
1 | // File: activitystream.js
2 |
3 | const {Client} = require('../client');
4 |
5 | /**
6 | * `ActivityStream` provides methods to interact with Zendesk ticket activities.
7 | * This class extends the base Client class and is tailored to fetch activity data.
8 | * @see {@link https://developer.zendesk.com/api-reference/ticketing/tickets/activity_stream/ | Zendesk Activity Stream API}
9 | * @example
10 | * const client = new Client({ /* ...options... * / });
11 | * const activities = await client.activitystream.list();
12 | */
13 | class ActivityStream extends Client {
14 | /**
15 | * Creates an instance of the ActivityStream client.
16 | * @param {object} options - Configuration options for the client.
17 | */
18 | constructor(options) {
19 | super(options);
20 | this.jsonAPINames = ['activities', 'activity'];
21 | }
22 |
23 | /**
24 | * Lists all ticket activities from the Zendesk API.
25 | * @returns {Array