node-zendesk
repository·master·Indexed 18 days ago
https://github.com/blakmatrix/node-zendeskA Zendesk API client library for Node.js and the browser (version 6.0.1). It provides a versatile gateway to the Zendesk Customer Support Platform, supporting core, helpdesk, services, and voice APIs. Features include built-in TypeScript definitions, support for Basic and OAuth authentication, request throttling, custom transport configurations, and side-loading of related records.
What's inside node-zendesk
- node-zendesk is a robust, lightweight Zendesk API client wrapper designed for seamless API interactions. It is optimized for performance and provides top-notch support for both JavaScript and TypeScript, making it suitable for modern development environments.
Use TypeScript with node-zendesk
masterSince versionv5.0.0,node-zendeskincludes built-in TypeScript definitions. You do not need to install separate type definitions (like@types/node-zendesk); the library provides accurate, up-to-date types automatically upon installation.Get started with node-zendesk
masterTo usenode-zendeskfor interacting with the Zendesk API in your Node.js environment, ensure you have a JavaScript or TypeScript project set up and are comfortable with asynchronous programming (Promises/async/await).Enable debug logging in the Zendesk client
masterYou can enable or disable detailed debug logging by setting the
debugproperty in the client configuration object. When set totrue, the client will output additional diagnostic information to help troubleshoot issues.const clientOptions = { debug: true };Configure supported Zendesk API types
masterBy default,
node-zendeskuses thecoreAPI. To access other Zendesk APIs such ashelpdesk,services, orvoice, you must explicitly include them in theapiTypearray during client instantiation via thezendesk.createClientmethod.Available API types:
core(default)helpdeskservicesvoice
const clientOptions = { username: 'your_username', token: 'your_token', subdomain: 'your_subdomain', apiType: ['core', 'helpdesk', 'services', 'voice'], }; const client = zendesk.createClient(clientOptions);Provide custom headers in client options
masterWhen initializing the Zendesk client, you can include an object of additional HTTP headers by using the
customHeaderskey within the client options object. This allows you to pass arbitrary headers (e.g., for authentication, tracing, or custom middleware requirements) with every request made by the client.const clientOptions = { customHeaders: { 'X-Custom-Header': 'CustomValue' } };Install node-zendesk via npm
masterTo add
node-zendeskto your project, install it as a dependency using npm. This makes the library available for import in your application code.npm install --save node-zendeskSide-load related records using setSideLoad
masterSide-loading enables you to retrieve related records (such as groups or roles) in the same request as your primary record query. To enable this, call the
setSideLoadmethod on the relevant resource collection (e.g.,client.users) and pass an array of strings representing the names of the related records you wish to include.client.users.setSideLoad(['group', 'role']);Authenticate using OAuth Authentication
masterTo use an OAuth token instead of a username/token pair, pass the OAuth token to the
tokenkey and set theoauthoption totruewhen callingcreateClient.var zendesk = require('node-zendesk'); var client = zendesk.createClient({ token: 'your_oauth_token', oauth: true });Impersonate an end user
masterTo make API requests on behalf of a specific end user, you must use OAuth authentication with the
impersonatescope granted. When creating the client, provide the end user's email address in theasUserproperty.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' });Authenticate using Basic Authentication
masterYou can quickly set up access to the Zendesk API using a combination of your username, an API token, and your Zendesk subdomain. This is the standard method for administrative or service-account access.
var zendesk = require('node-zendesk'); var client = zendesk.createClient({ username: 'your_username', token: 'your_token', subdomain: 'your_subdomain' });Override default pagination settings
masterBy default,
node-zendeskoptimizes pagination for efficient retrieval of large datasets. If you need to customize the pagination behavior, you can pass aqueryobject to thezendesk.createClientoptions during instantiation. This allows you to specify parameters likepage.size.Warning: Overriding the default mechanism is not recommended. Furthermore, note that cursor-based pagination in the Zendesk API typically does not support retrieving more than 100 items for most cursor-based endpoints.
const clientOptions = { username: 'your_username', token: 'your_token', subdomain: 'your_subdomain', query: { page: { size: 1 } } }; const client = zendesk.createClient(clientOptions);