-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcf3b81
commit 8c9b3c4
Showing
18 changed files
with
367 additions
and
947 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Custom Headers | ||
|
||
You can provide additional custom headers for your requests: | ||
|
||
```js | ||
const clientOptions = { | ||
customHeaders: { | ||
'X-Custom-Header': 'CustomValue' | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Custom Logging | ||
|
||
`node-zendesk` provides an option to log to your own logger object. By default, it uses its own `ConsoleLogger`. To use a custom logger: | ||
|
||
```js | ||
const clientOptions = { | ||
username: 'your_username', | ||
token: 'your_token', | ||
subdomain: 'your_subdomain', | ||
logger: yourCustomLogger, | ||
debug: true | ||
}; | ||
const client = zendesk.createClient(clientOptions); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Custom Transport Configuration | ||
|
||
If you prefer not to use the default `cross-fetch`, you can configure a custom transport. Here's an example using `axios`: | ||
|
||
```js | ||
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(); | ||
``` | ||
|
||
This example demonstrates how to set up a client using `axios` as the transport mechanism instead of the default `cross-fetch`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Debug Logging | ||
|
||
Enable or disable debug logging using the `debug` property: | ||
|
||
```js | ||
const clientOptions = { | ||
debug: true | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Endpoint URI Override | ||
|
||
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. | ||
|
||
## Throttling | ||
|
||
Enable request throttling by setting the `throttle` flag: | ||
|
||
```js | ||
const clientOptions = { | ||
throttle: true | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
order:5 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# API Types | ||
|
||
`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: | ||
|
||
```js | ||
client.helpdesk.categories.list(); | ||
``` | ||
|
||
Currently, there are only `helpdesk`, `services`, and `voice` and you can use them all by including the upon client instantiation as follows: | ||
|
||
```js | ||
const clientOptions = { | ||
username: 'your_username', | ||
token: 'your_token', | ||
subdomain: 'your_subdomain', | ||
apiType: ['core', 'helpdesk', 'services', 'voice'], | ||
}; | ||
const client = zendesk.createClient(clientOptions); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Pagination | ||
|
||
`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: | ||
|
||
```js | ||
const clientOptions = { | ||
username: 'your_username', | ||
token: 'your_token', | ||
subdomain: 'your_subdomain', | ||
query: { page: { size: 1 } } | ||
}; | ||
const client = zendesk.createClient(clientOptions); | ||
``` | ||
|
||
::: danger **Warning** | ||
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. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Side-Loading | ||
|
||
Side-loading allows you to retrieve related records along with the primary records you're querying. To set side-loading, use the `setSideLoad` method: | ||
|
||
```js | ||
client.users.setSideLoad(['group', 'role']); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Throttling | ||
|
||
Enable request throttling by setting the `throttle` flag: | ||
|
||
```js | ||
const clientOptions = { | ||
throttle: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
order: 2 | ||
--- | ||
|
||
# Authentication | ||
|
||
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. | ||
|
||
## Basic Authentication | ||
|
||
Using a combination of your username, token, and subdomain, you can quickly set up basic authentication: | ||
|
||
::: code-group | ||
|
||
```js | ||
var zendesk = require('node-zendesk'); | ||
|
||
var client = zendesk.createClient({ | ||
username: 'your_username', | ||
token: 'your_token', | ||
subdomain: 'your_subdomain' | ||
}); | ||
``` | ||
|
||
```ts | ||
import {createClient} from 'node-zendesk' | ||
|
||
var client = createClient({ | ||
username: 'your_username', | ||
token: 'your_token', | ||
subdomain: 'your_subdomain' | ||
}); | ||
``` | ||
::: | ||
|
||
## OAuth Authentication | ||
|
||
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. | ||
|
||
::: code-group | ||
```js | ||
var zendesk = require('node-zendesk'); | ||
|
||
var client = zendesk.createClient({ | ||
token: 'your_oauth_token', | ||
oauth: true | ||
}); | ||
``` | ||
|
||
```ts | ||
import {createClient} from 'node-zendesk' | ||
|
||
var client = zendesk.createClient({ | ||
token: 'your_oauth_token', | ||
oauth: true | ||
}); | ||
``` | ||
::: | ||
|
||
## Impersonation | ||
|
||
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: | ||
|
||
::: code-group | ||
```js | ||
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' | ||
}); | ||
``` | ||
|
||
```ts | ||
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' | ||
}); | ||
``` | ||
::: | ||
|
||
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. |
Oops, something went wrong.