### Install Project Dependencies Source: https://github.com/blakmatrix/node-zendesk/blob/master/CONTRIBUTING.md Install all necessary development and runtime dependencies for the node-zendesk project using npm. ```bash npm install ``` -------------------------------- ### Install node-zendesk using npm Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/installation.md Use this command to add node-zendesk as a dependency to your project. ```shell npm install --save node-zendesk ``` -------------------------------- ### Configure Zendesk Client with Axios Transport Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/custom-transport.md Use this snippet to set up a Zendesk client with axios as the custom HTTP transport. Ensure axios is installed and imported. ```javascript const transportConfigUsingAxios = { async transportFn(uri, options) { // Convert the options to be compatible with axios const requestOptions = { ...options, url: uri, method: options.method || 'GET', data: options.body, }; try { const response = await axios(requestOptions); return response; } catch (error) { if (error.response) { return error.response; } throw error; } }, responseAdapter(response) { return { json: () => Promise.resolve(response.data), status: response.status, headers: { get: (headerName) => response.headers[headerName.toLowerCase()], }, statusText: response.statusText, }; }, }; const setupClient = (config) => { return zd.createClient({ username: ZENDESK_USERNAME, subdomain: ZENDESK_SUBDOMAIN, token: ZENDESK_TOKEN, transportConfig: transportConfigUsingAxios, ...config, }); }; async function foo() { try { const client = setupClient({debug: false}); const result = await client.users.list(); console.dir(result); } catch (error) { console.error(`Failed: ${error.message}`); } } foo(); ``` -------------------------------- ### Initialize and Use Zendesk Client Source: https://github.com/blakmatrix/node-zendesk/blob/master/ReadMe.md Demonstrates how to create a Zendesk client instance with authentication credentials and fetch a list of users. Ensure you replace placeholder values with your actual Zendesk credentials. ```javascript var zendesk = require('node-zendesk'); // or `import {createClient} from 'node-zendesk'` if using typescript var client = zendesk.createClient({ username: 'username', token: 'token', subdomain: 'subdomain' }); client.users.list().then(users => { console.log('Total Users:', users.length); console.log('User Names:', users.map(user => user.name)); }).catch(error => { console.error(`Failed to get list of users: ${error.message}`); }); ``` -------------------------------- ### Instantiate Client with Multiple API Types Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/manage-apis.md Instantiate the Zendesk client with an array of desired API types. This allows the client to access multiple Zendesk API endpoints, such as core, helpdesk, services, and voice, within a single client instance. ```javascript const clientOptions = { username: 'your_username', token: 'your_token', subdomain: 'your_subdomain', apiType: ['core', 'helpdesk', 'services', 'voice'], }; const client = zendesk.createClient(clientOptions); ``` -------------------------------- ### Basic Authentication with JavaScript Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/authentication.md Use this method for simple API access by providing your username, API token, and subdomain. ```javascript var zendesk = require('node-zendesk'); var client = zendesk.createClient({ username: 'your_username', token: 'your_token', subdomain: 'your_subdomain' }); ``` -------------------------------- ### Initialize node-zendesk with a Custom Logger Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/custom-logging.md Pass your custom logger object to the `logger` option when creating a new zendesk client instance. Ensure your logger object has methods that node-zendesk expects, such as `info`, `warn`, `error`, etc. ```javascript const clientOptions = { username: 'your_username', token: 'your_token', subdomain: 'your_subdomain', logger: yourCustomLogger, debug: true }; const client = zendesk.createClient(clientOptions); ``` -------------------------------- ### Basic Authentication with TypeScript Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/authentication.md TypeScript equivalent for basic authentication, requiring the same credentials. ```typescript import {createClient} from 'node-zendesk' var client = createClient({ username: 'your_username', token: 'your_token', subdomain: 'your_subdomain' }); ``` -------------------------------- ### Clone Repository and Add Upstream Remote Source: https://github.com/blakmatrix/node-zendesk/blob/master/CONTRIBUTING.md Clone the node-zendesk repository and set up the upstream remote to track changes from the original repository. ```bash git clone https://github.com/[your-username]/node-zendesk.git git remote add upstream https://github.com/blakmatrix/node-zendesk.git ``` -------------------------------- ### Run Linting Checks Source: https://github.com/blakmatrix/node-zendesk/blob/master/CONTRIBUTING.md Execute the linting process using npm to ensure code quality and adherence to coding standards. ```bash npm run lint ``` -------------------------------- ### OAuth Authentication with JavaScript Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/authentication.md Authenticate using an OAuth token by setting the 'oauth' option to true. ```javascript var zendesk = require('node-zendesk'); var client = zendesk.createClient({ token: 'your_oauth_token', oauth: true }); ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/debugging.md Set the `debug` property to `true` in the client options object to enable debug logging. This is useful for troubleshooting API interactions. ```javascript const clientOptions = { debug: true }; ``` -------------------------------- ### Access Helpdesk API Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/manage-apis.md Call the helpdesk API explicitly to access its functionalities. This is useful when you need to interact with Zendesk's helpdesk-specific features. ```javascript client.helpdesk.categories.list(); ``` -------------------------------- ### Impersonation Authentication with JavaScript Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/authentication.md Make API requests on behalf of end-users by providing their email with the 'asUser' option. Requires OAuth. ```javascript var zendesk = require('node-zendesk'); var client = createClient({ username: 'your_username', token: 'your_oauth_token', subdomain: 'your_subdomain', oauth: true, asUser: 'end-user@example.com' }); ``` -------------------------------- ### Adding Custom Headers to Client Options Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/custom-headers.md Configure custom headers by passing an object to the `customHeaders` property within the client's options. This is useful for adding unique identifiers or metadata to your requests. ```javascript const clientOptions = { customHeaders: { 'X-Custom-Header': 'CustomValue' } }; ``` -------------------------------- ### OAuth Authentication with TypeScript Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/authentication.md TypeScript version for OAuth authentication, utilizing an OAuth token and the 'oauth' flag. ```typescript import {createClient} from 'node-zendesk' var client = createClient({ token: 'your_oauth_token', oauth: true }); ``` -------------------------------- ### Impersonation Authentication with TypeScript Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/authentication.md TypeScript implementation for impersonation, allowing requests as a specific end-user via the 'asUser' parameter. Requires OAuth. ```typescript import {createClient} from 'node-zendesk' var client = createClient({ username: 'your_username', token: 'your_oauth_token', subdomain: 'your_subdomain', oauth: true, asUser: 'end-user@example.com' }); ``` -------------------------------- ### Override Default Pagination Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/pagination.md Customize pagination size by setting the 'page.size' option during client creation. Use this for specific scenarios requiring different page sizes. ```javascript const clientOptions = { username: 'your_username', token: 'your_token', subdomain: 'your_subdomain', query: { page: { size: 1 } } }; const client = zendesk.createClient(clientOptions); ``` -------------------------------- ### Enable Request Throttling Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/throttling.md Set the `throttle` flag to `true` in the client options to enable request throttling. This helps manage API rate limits. ```javascript const clientOptions = { throttle: true }; ``` -------------------------------- ### Set Side-Loading for Related Records Source: https://github.com/blakmatrix/node-zendesk/blob/master/docs/guide/Guide/Advanced/sideload.md Use `setSideLoad` to specify related records like 'group' and 'role' to be included in subsequent API requests. This method configures the client for side-loading. ```javascript client.users.setSideLoad(['group', 'role']); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.