node-zendesk

repository·master·Indexed 18 days ago

https://github.com/blakmatrix/node-zendesk

A 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.

Tokens
19.3K
Snippets
95
Records
106
Agent score
63%

What's inside node-zendesk

  1. Overview of node-zendesk

    master
    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.
  2. Configure supported Zendesk API types

    master

    By default, node-zendesk uses the core API. To access other Zendesk APIs such as helpdesk, services, or voice, you must explicitly include them in the apiType array during client instantiation via the zendesk.createClient method.

    Available API types:

    • core (default)
    • helpdesk
    • services
    • voice
    const clientOptions = {
      username: 'your_username',
      token: 'your_token',
      subdomain: 'your_subdomain',
      apiType: ['core', 'helpdesk', 'services', 'voice'],
    };
    const client = zendesk.createClient(clientOptions);
  3. Provide custom headers in client options

    master

    When initializing the Zendesk client, you can include an object of additional HTTP headers by using the customHeaders key 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'
      }
    };
  4. Side-load related records using setSideLoad

    master

    Side-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 setSideLoad method 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']);
  5. Impersonate an end user

    master

    To make API requests on behalf of a specific end user, you must use OAuth authentication with the impersonate scope granted. When creating the client, provide the end user's email address in the asUser property.

    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'
    });
  6. Authenticate using Basic Authentication

    master

    You 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'
    });
  7. Override default pagination settings

    master

    By default, node-zendesk optimizes pagination for efficient retrieval of large datasets. If you need to customize the pagination behavior, you can pass a query object to the zendesk.createClient options during instantiation. This allows you to specify parameters like page.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);