Registry / crm-productivity / freshdesk-api

freshdesk-api

JSON →
library3.1.0jsnpmunverified

freshdesk-api is a Node.js wrapper for the Freshdesk v2 API, providing a convenient and typed interface for interacting with Freshdesk services. The current stable version is 3.1.0. The package has an active release cadence, with significant updates and new features being added regularly, alongside dependency maintenance and bug fixes. It differentiates itself by offering full TypeScript support and leveraging `undici` for efficient HTTP requests, though note that attachment handling still relies on `form-data`. This client is designed for server-side Node.js applications that need to integrate with Freshdesk for ticket management, contact synchronization, and other API operations, offering a more modern alternative to older v1 API clients.

npm install freshdesk-api
INSTALL
IMPORT
SIG · FRESHDESK-API
F
freshdesk-api
crm-productivityjavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Freshdesk
import Freshdesk from 'freshdesk-api'
import { Freshdesk } from 'freshdesk-api'
The main Freshdesk API client class is exported as the default module export.
FreshdeskError
import Freshdesk from 'freshdesk-api'; /* then use Freshdesk.FreshdeskError */
import { FreshdeskError } from 'freshdesk-api'
FreshdeskError is a static property of the default Freshdesk class, useful for `instanceof` checks in catch blocks for specific API errors.
Ticket, FreshdeskOptions
import type { Ticket, FreshdeskOptions } from 'freshdesk-api'
Import types (interfaces, enums) separately using `import type` for clarity and to enable tree-shaking in TypeScript projects.

This quickstart initializes the Freshdesk API client using environment variables and demonstrates how to create a new ticket and then fetch its details, including robust error handling.

import Freshdesk from 'freshdesk-api'; // Configure Freshdesk API client using environment variables for security const domain = process.env.FRESHDESK_DOMAIN ?? 'https://yourdomain.freshdesk.com'; const apiKey = process.env.FRESHDESK_API_KEY ?? 'yourApiKey'; // Warn if using placeholder credentials if (apiKey === 'yourApiKey' || domain === 'https://yourdomain.freshdesk.com') { console.warn("WARNING: Please set FRESHDESK_DOMAIN and FRESHDESK_API_KEY environment variables."); console.warn("Using placeholder credentials which will likely result in authentication errors."); } const freshdesk = new Freshdesk(domain, apiKey); async function createAndFetchTicket() { try { const ticketData = { name: "New Customer Inquiry", email: "inquiry@example.com", subject: "Problem with recent order #12345", description: "The items in my order were incorrect.", status: 2, // Open priority: 1 // Low }; console.log("Attempting to create a new ticket..."); const newTicket = await freshdesk.createTicket(ticketData); console.log("Ticket created successfully:", newTicket); console.log(`Fetching ticket ${newTicket.id}...`); const fetchedTicket = await freshdesk.getTicket(newTicket.id); console.log("Fetched ticket details:", fetchedTicket); } catch (error: any) { console.error("An error occurred:", error.message); if (error.response?.status) { console.error("HTTP Status:", error.response.status); console.error("Response data:", error.response.data); } if (error instanceof Freshdesk.FreshdeskError) { console.error("Freshdesk API specific error details:", error.extra); } } } createAndFetchTicket();
Debug
Known issues
breakingVersion 3.0.0 removed the internal dependency and integration with `bluebird` for promisification. Users who relied on methods like `freshdesk.getTicketAsync` for promisified calls will need to update their code to use native async/await or standard Promise wrappers.
fix
Migrate from `bluebird`'s promisified methods (e.g., `getTicketAsync`) to native async/await syntax or explicit Promise wrapping for API calls (e.g., `await freshdesk.getTicket(...)`).
affects: >=3.0.0
breakingIn version 2.13.0, the underlying HTTP client library was replaced from `request` to `axios`, and subsequently to `undici`. While efforts were made to maintain API compatibility, users relying on specific behaviors or configuration options of the previous `request` library might encounter subtle breaking changes.
fix
Review any custom HTTP client configurations or assumptions made about the underlying `request` library. Most direct API calls should remain compatible, but behavior for edge cases or advanced HTTP options might differ.
affects: >=2.13.0
gotchaThe package uses `Undici` as its HTTP client (since v2.13.0), which is not compatible with `nock` for mocking network requests. Only requests involving `form-data` (e.g., attachments) still use Node.js `net` module and can be mocked with `nock`.
fix
When testing or mocking `freshdesk-api`, use `Undici`'s built-in mocking functionality for most requests. For form-data/attachment requests, `nock` remains a viable option. Alternatively, use a client-agnostic mock server.
affects: >=2.13.0
gotchaOlder versions of the client (prior to v3.1.0) could return an 'unexpected end of JSON input' error when Freshdesk API rate limits were exceeded, due to an incomplete JSON response from the server.
fix
Upgrade to `freshdesk-api` version 3.1.0 or newer, which includes a fix to correctly handle rate limit responses and return the `retry-after` header in `FreshdeskError`.
affects: <3.1.0
Errors
Common errors & fixes
Error: unexpected end of JSON input
This error often occurs in older versions when the Freshdesk API returns an incomplete JSON response, typically due to rate limiting or an internal server error.
fix
Upgrade to `freshdesk-api` version 3.1.0 or newer. Ensure your API calls respect Freshdesk's rate limits. Check the `FreshdeskError` object for `retry-after` details.
Error: Request failed with status code 401
The API key or domain provided for authentication is incorrect or unauthorized.
fix
Double-check your `FRESHDESK_DOMAIN` and `FRESHDESK_API_KEY` environment variables or configuration. Ensure the API key has the necessary permissions for the operations being performed.
TypeError: freshdesk.createTicket is not a function
This usually happens when `Freshdesk` is imported incorrectly as a named import instead of a default import, or when an older CommonJS `require` call is used in an ESM context without proper interoperability.
fix
For ESM, use `import Freshdesk from 'freshdesk-api';`. For CommonJS, use `const Freshdesk = require('freshdesk-api');`. Ensure you are not destructuring the `Freshdesk` class from the import.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
43 hits · last 30 days
node
40
OpenAI (training)
1
Resources