Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

feat(zendesk): add OAuth2 auth alongside API token (#15672)

Kishan Parmarcd78f560682f
diff --git a/bun.lock b/bun.lock
index 23256f960f4..980e7617bde 100644
--- a/bun.lock
+++ b/bun.lock
@@ -10079,7 +10079,7 @@
},
"packages/pieces/community/zendesk": {
"name": "@activepieces/piece-zendesk",
- "version": "0.3.0",
+ "version": "0.4.0",
"dependencies": {
"@activepieces/core-piece-types": "workspace:*",
"@activepieces/core-utils": "workspace:*",
@@ -10089,6 +10089,7 @@
},
"devDependencies": {
"tslib": "2.6.2",
+ "vitest": "3.2.6",
},
},
"packages/pieces/community/zendesk-sell": {
diff --git a/packages/pieces/community/zendesk/package.json b/packages/pieces/community/zendesk/package.json
index 6efad39eb72..094de48cd91 100644
--- a/packages/pieces/community/zendesk/package.json
+++ b/packages/pieces/community/zendesk/package.json
@@ -1,12 +1,13 @@
{
"name": "@activepieces/piece-zendesk",
- "version": "0.3.0",
+ "version": "0.4.0",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
"bundle": "node ../../../../dist/packages/cli/src/index.js pieces bundle",
- "lint": "eslint 'src/**/*.ts'"
+ "lint": "eslint 'src/**/*.ts'",
+ "test": "vitest run"
},
"dependencies": {
"@activepieces/pieces-common": "workspace:*",
@@ -16,6 +17,7 @@
"@activepieces/core-utils": "workspace:*"
},
"devDependencies": {
- "tslib": "2.6.2"
+ "tslib": "2.6.2",
+ "vitest": "3.2.6"
}
}
diff --git a/packages/pieces/community/zendesk/src/index.ts b/packages/pieces/community/zendesk/src/index.ts
index ac61c49c718..48da21b7b21 100644
--- a/packages/pieces/community/zendesk/src/index.ts
+++ b/packages/pieces/community/zendesk/src/index.ts
@@ -1,10 +1,8 @@
import { createCustomApiCallAction } from '@activepieces/pieces-common';
-import {
- PieceAuth,
- Property,
- createPiece,
-} from '@activepieces/pieces-framework';
+import { createPiece } from '@activepieces/pieces-framework';
import { PieceCategory } from '@activepieces/pieces-framework';
+import { zendeskAuth } from './lib/auth';
+import { getZendeskAuthorizationHeader, getZendeskBaseUrl } from './lib/common/client';
import { newTicketInView } from './lib/trigger/new-ticket-in-view';
import { newTicket } from './lib/trigger/new-ticket';
import { updatedTicket } from './lib/trigger/updated-ticket';
@@ -33,36 +31,6 @@ import { findGroupAction } from './lib/actions/find-group';
import { findLatestCommentAction } from './lib/actions/find-latest-comment';
import { updateUserAction } from './lib/actions/update-user';
-const markdownProperty = `
-**Organization**: The organization name can be found in the URL (e.g https://ORGANIZATION_NAME.zendesk.com).
-
-**Agent Email**: The email you use to log in to Zendesk.
-
-**API Token**: You can find this in the Zendesk Admin Panel under Settings > APIs > Zendesk API.
-`;
-
-export const zendeskAuth = PieceAuth.CustomAuth({
- description: markdownProperty,
- props: {
- email: Property.ShortText({
- displayName: 'Agent Email',
- description: 'The email address you use to login to Zendesk',
- required: true,
- }),
- token: Property.ShortText({
- displayName: 'Token',
- description: 'The API token you can generate in Zendesk',
- required: true,
- }),
- subdomain: Property.ShortText({
- displayName: 'Organization (e.g activepieceshelp)',
- description: 'The subdomain of your Zendesk instance',
- required: true,
- }),
- },
- required: true,
-});
-
export const zendesk = createPiece({
displayName: 'Zendesk',
description: 'Customer service software and support ticket system',
@@ -91,18 +59,10 @@ export const zendesk = createPiece({
findLatestCommentAction,
updateUserAction,
createCustomApiCallAction({
- baseUrl: (auth) =>
- auth?
- `https://${
- auth.props.subdomain
- }.zendesk.com/api/v2` : '',
+ baseUrl: (auth) => (auth ? getZendeskBaseUrl(auth) : ''),
auth: zendeskAuth,
authMapping: async (auth) => ({
- Authorization: `Basic ${Buffer.from(
- `${auth.props.email}/token:${
- auth.props.token
- }`
- ).toString('base64')}`,
+ Authorization: getZendeskAuthorizationHeader(auth),
}),
}),
],
diff --git a/packages/pieces/community/zendesk/src/lib/actions/add-comment-to-ticket.ts b/packages/pieces/community/zendesk/src/lib/actions/add-comment-to-ticket.ts
index 0ae25e78940..0c5a5546788 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/add-comment-to-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/add-comment-to-ticket.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { ticketIdDropdown } from '../common/props';
export const addCommentToTicketAction = createAction({
@@ -67,17 +67,11 @@ export const addCommentToTicketAction = createAction({
const resolveUserByEmail = async (email: string) => {
try {
const response = await httpClient.sendRequest({
- url: `https://${
- authentication.props.subdomain
- }.zendesk.com/api/v2/users/search.json?query=email:${encodeURIComponent(
+ url: `${getZendeskBaseUrl(authentication)}/users/search.json?query=email:${encodeURIComponent(
email
)}`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const users = (response.body as { users: Array<{ id: number }> }).users;
@@ -126,16 +120,12 @@ export const addCommentToTicketAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}.json`,
+ url: `${getZendeskBaseUrl(authentication)}/tickets/${ticket_id}.json`,
method: HttpMethod.PUT,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
ticket,
},
diff --git a/packages/pieces/community/zendesk/src/lib/actions/add-tag-to-ticket.ts b/packages/pieces/community/zendesk/src/lib/actions/add-tag-to-ticket.ts
index 4f0dbc7c954..8c022780aa5 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/add-tag-to-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/add-tag-to-ticket.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { ticketIdDropdown } from '../common/props';
export const addTagToTicketAction = createAction({
@@ -60,16 +60,12 @@ export const addTagToTicketAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags.json`,
+ url: `${getZendeskBaseUrl(authentication)}/tickets/${ticket_id}/tags.json`,
method: HttpMethod.PUT,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body,
});
diff --git a/packages/pieces/community/zendesk/src/lib/actions/attach-file-to-ticket.ts b/packages/pieces/community/zendesk/src/lib/actions/attach-file-to-ticket.ts
index 4a7fa998d34..52468c0aace 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/attach-file-to-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/attach-file-to-ticket.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { ticketIdDropdown } from '../common/props';
export const attachFileToTicketAction = createAction({
@@ -36,16 +36,12 @@ export const attachFileToTicketAction = createAction({
const uploadResponse = await httpClient.sendRequest<{
upload: { token: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/uploads.json?filename=${encodeURIComponent(file.filename)}`,
+ url: `${getZendeskBaseUrl(authentication)}/uploads.json?filename=${encodeURIComponent(file.filename)}`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/octet-stream',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: file.data,
});
@@ -53,16 +49,12 @@ export const attachFileToTicketAction = createAction({
// Then attach the uploaded file to the ticket
const attachResponse = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}.json`,
+ url: `${getZendeskBaseUrl(authentication)}/tickets/${ticket_id}.json`,
method: HttpMethod.PUT,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
ticket: {
comment: {
diff --git a/packages/pieces/community/zendesk/src/lib/actions/create-organization.ts b/packages/pieces/community/zendesk/src/lib/actions/create-organization.ts
index e168048b07f..c140e470ec1 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/create-organization.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/create-organization.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { groupIdDropdown } from '../common/props';
export const createOrganizationAction = createAction({
@@ -61,13 +61,9 @@ export const createOrganizationAction = createAction({
try {
const authentication = auth;
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organization_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/organization_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fields = (response.body as { organization_fields: Array<{
@@ -232,13 +228,9 @@ export const createOrganizationAction = createAction({
if (organization_fields && typeof organization_fields === 'object') {
try {
const fieldsResponse = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organization_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/organization_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fieldDefinitions = (fieldsResponse.body as { organization_fields: Array<{
@@ -275,16 +267,12 @@ export const createOrganizationAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organizations.json`,
+ url: `${getZendeskBaseUrl(authentication)}/organizations.json`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
organization,
},
diff --git a/packages/pieces/community/zendesk/src/lib/actions/create-ticket.ts b/packages/pieces/community/zendesk/src/lib/actions/create-ticket.ts
index 47611d8378a..0a9182eb85c 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/create-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/create-ticket.ts
@@ -3,11 +3,11 @@ import {
Property,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { organizationIdDropdown, brandIdDropdown, problemTicketIdDropdown, groupIdDropdown } from '../common/props';
export const createTicketAction = createAction({
@@ -137,13 +137,9 @@ export const createTicketAction = createAction({
try {
const authentication = auth;
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/ticket_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/ticket_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fields = (response.body as { ticket_fields: Array<{
@@ -335,15 +331,11 @@ export const createTicketAction = createAction({
const resolveUserByEmail = async (email: string) => {
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/users/search.json?query=email:${encodeURIComponent(email)}`,
+ url: `${getZendeskBaseUrl(authentication)}/users/search.json?query=email:${encodeURIComponent(email)}`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
-
+
const users = (response.body as { users: Array<{ id: number }> }).users;
return users.length > 0 ? users[0].id : null;
} catch (error) {
@@ -422,13 +414,9 @@ export const createTicketAction = createAction({
if (custom_fields && typeof custom_fields === 'object') {
try {
const fieldsResponse = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/ticket_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/ticket_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fieldDefinitions = (fieldsResponse.body as { ticket_fields: Array<{
@@ -463,16 +451,12 @@ export const createTicketAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets.json`,
+ url: `${getZendeskBaseUrl(authentication)}/tickets.json`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
ticket,
},
diff --git a/packages/pieces/community/zendesk/src/lib/actions/create-user.ts b/packages/pieces/community/zendesk/src/lib/actions/create-user.ts
index f1a96cca3d2..71e6652cd24 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/create-user.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/create-user.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import {
organizationIdDropdown,
customRoleIdDropdown,
@@ -292,13 +292,9 @@ export const createUserAction = createAction({
if (user_fields && typeof user_fields === 'object') {
try {
const fieldsResponse = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/user_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/user_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const defs = (fieldsResponse.body as { user_fields: Array<{ id: number; key: string; type: string }> }).user_fields;
@@ -358,16 +354,12 @@ export const createUserAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/users.json`,
+ url: `${getZendeskBaseUrl(authentication)}/users.json`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: requestBody,
});
diff --git a/packages/pieces/community/zendesk/src/lib/actions/delete-user.ts b/packages/pieces/community/zendesk/src/lib/actions/delete-user.ts
index 8edf0fab702..641d95cf872 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/delete-user.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/delete-user.ts
@@ -3,11 +3,11 @@ import {
Property,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { userIdDropdown } from '../common/props';
export const deleteUserAction = createAction({
@@ -39,13 +39,9 @@ export const deleteUserAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/users/${user_id}.json`,
+ url: `${getZendeskBaseUrl(authentication)}/users/${user_id}.json`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
return {
diff --git a/packages/pieces/community/zendesk/src/lib/actions/find-agent.ts b/packages/pieces/community/zendesk/src/lib/actions/find-agent.ts
index 469fd10ba25..b44de977b36 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/find-agent.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/find-agent.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
interface ZendeskAgent {
id: number;
@@ -59,7 +59,7 @@ export const findAgentAction = createAction({
}
try {
- let url: string | undefined = `https://${authentication.props.subdomain}.zendesk.com/api/v2/users.json?role=agent&per_page=100`;
+ let url: string | undefined = `${getZendeskBaseUrl(authentication)}/users.json?role=agent&per_page=100`;
let matchedAgent: ZendeskAgent | undefined;
while (url && !matchedAgent) {
@@ -67,11 +67,7 @@ export const findAgentAction = createAction({
const response = await httpClient.sendRequest<ZendeskUsersResponse & { next_page?: string }>({
url: currentUrl,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const agents = response.body.users || [];
diff --git a/packages/pieces/community/zendesk/src/lib/actions/find-group.ts b/packages/pieces/community/zendesk/src/lib/actions/find-group.ts
index 4e880ffb165..89340bc1a63 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/find-group.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/find-group.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
interface ZendeskGroup {
id: number;
@@ -42,7 +42,7 @@ export const findGroupAction = createAction({
}
try {
- let url: string | undefined = `https://${authentication.props.subdomain}.zendesk.com/api/v2/groups.json?per_page=100`;
+ let url: string | undefined = `${getZendeskBaseUrl(authentication)}/groups.json?per_page=100`;
let matchedGroup: ZendeskGroup | undefined;
while (url && !matchedGroup) {
@@ -50,11 +50,7 @@ export const findGroupAction = createAction({
const response = await httpClient.sendRequest<ZendeskGroupsResponse & { next_page?: string }>({
url: currentUrl,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const groups = response.body.groups || [];
diff --git a/packages/pieces/community/zendesk/src/lib/actions/find-latest-comment.ts b/packages/pieces/community/zendesk/src/lib/actions/find-latest-comment.ts
index dda1355f6a8..93d11736e55 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/find-latest-comment.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/find-latest-comment.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { ticketIdDropdown } from '../common/props';
interface ZendeskComment {
@@ -51,7 +51,7 @@ export const findLatestCommentAction = createAction({
const { ticket_id, include_private } = propsValue;
try {
- let url: string | undefined = `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/comments?sort_order=desc`;
+ let url: string | undefined = `${getZendeskBaseUrl(authentication)}/tickets/${ticket_id}/comments?sort_order=desc`;
let latestComment: ZendeskComment | undefined;
let isFirstPage = true;
@@ -60,11 +60,7 @@ export const findLatestCommentAction = createAction({
const response = await httpClient.sendRequest<ZendeskCommentsResponse & { next_page?: string }>({
url: currentUrl,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const comments = response.body.comments || [];
diff --git a/packages/pieces/community/zendesk/src/lib/actions/find-organization.ts b/packages/pieces/community/zendesk/src/lib/actions/find-organization.ts
index 2315e01692c..5edae8f6187 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/find-organization.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/find-organization.ts
@@ -3,11 +3,11 @@ import {
Property,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
export const findOrganizationAction = createAction({
auth: zendeskAuth,
@@ -160,13 +160,9 @@ export const findOrganizationAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/search.json?${searchParams.toString()}`,
+ url: `${getZendeskBaseUrl(authentication)}/search.json?${searchParams.toString()}`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const responseBody = response.body as {
diff --git a/packages/pieces/community/zendesk/src/lib/actions/find-tickets.ts b/packages/pieces/community/zendesk/src/lib/actions/find-tickets.ts
index 209f098e772..30f527478d5 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/find-tickets.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/find-tickets.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { isEmpty } from '@activepieces/pieces-framework';
import dayjs from 'dayjs'
@@ -284,15 +284,9 @@ export const findTicketsAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${
- authentication.props.subdomain
- }.zendesk.com/api/v2/search.json?${searchParams.toString()}`,
+ url: `${getZendeskBaseUrl(authentication)}/search.json?${searchParams.toString()}`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const responseBody = response.body as {
diff --git a/packages/pieces/community/zendesk/src/lib/actions/find-user.ts b/packages/pieces/community/zendesk/src/lib/actions/find-user.ts
index 49c79bde176..50e0b7785c5 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/find-user.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/find-user.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
export const findUserAction = createAction({
auth: zendeskAuth,
@@ -183,15 +183,9 @@ export const findUserAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${
- authentication.props.subdomain
- }.zendesk.com/api/v2/search.json?${searchParams.toString()}`,
+ url: `${getZendeskBaseUrl(authentication)}/search.json?${searchParams.toString()}`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const responseBody = response.body as {
diff --git a/packages/pieces/community/zendesk/src/lib/actions/remove-tag-from-ticket.ts b/packages/pieces/community/zendesk/src/lib/actions/remove-tag-from-ticket.ts
index 8c2e078f671..43b958ebef9 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/remove-tag-from-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/remove-tag-from-ticket.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { ticketIdDropdown } from '../common/props';
export const removeTagFromTicketAction = createAction({
@@ -35,16 +35,12 @@ export const removeTagFromTicketAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags.json`,
+ url: `${getZendeskBaseUrl(authentication)}/tickets/${ticket_id}/tags.json`,
method: HttpMethod.DELETE,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
tags: tags,
},
diff --git a/packages/pieces/community/zendesk/src/lib/actions/update-organization.ts b/packages/pieces/community/zendesk/src/lib/actions/update-organization.ts
index 476fede0452..146da350065 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/update-organization.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/update-organization.ts
@@ -3,11 +3,11 @@ import {
Property,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { organizationIdDropdown, groupIdDropdown } from '../common/props';
export const updateOrganizationAction = createAction({
@@ -65,13 +65,9 @@ export const updateOrganizationAction = createAction({
try {
const authentication = auth;
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organization_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/organization_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fields = (response.body as { organization_fields: Array<{
@@ -239,13 +235,9 @@ export const updateOrganizationAction = createAction({
if (organization_fields && typeof organization_fields === 'object') {
try {
const fieldsResponse = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organization_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/organization_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fieldDefinitions = (fieldsResponse.body as { organization_fields: Array<{
@@ -286,16 +278,12 @@ export const updateOrganizationAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organizations/${organization_id}.json`,
+ url: `${getZendeskBaseUrl(authentication)}/organizations/${organization_id}.json`,
method: HttpMethod.PUT,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
organization,
},
diff --git a/packages/pieces/community/zendesk/src/lib/actions/update-ticket.ts b/packages/pieces/community/zendesk/src/lib/actions/update-ticket.ts
index a98db26572b..d16a0e9668c 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/update-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/update-ticket.ts
@@ -1,10 +1,10 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import {
organizationIdDropdown,
ticketIdDropdown,
@@ -129,13 +129,9 @@ export const updateTicketAction = createAction({
try {
const authentication = auth;
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/ticket_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/ticket_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fields = (response.body as { ticket_fields: Array<{
@@ -332,17 +328,11 @@ export const updateTicketAction = createAction({
const resolveUserByEmail = async (email: string) => {
try {
const response = await httpClient.sendRequest({
- url: `https://${
- authentication.props.subdomain
- }.zendesk.com/api/v2/users/search.json?query=email:${encodeURIComponent(
+ url: `${getZendeskBaseUrl(authentication)}/users/search.json?query=email:${encodeURIComponent(
email
)}`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const users = (response.body as { users: Array<{ id: number }> }).users;
@@ -454,13 +444,9 @@ export const updateTicketAction = createAction({
if (custom_fields && typeof custom_fields === 'object') {
try {
const fieldsResponse = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/ticket_fields.json`,
+ url: `${getZendeskBaseUrl(authentication)}/ticket_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
const fieldDefinitions = (fieldsResponse.body as { ticket_fields: Array<{
@@ -499,16 +485,12 @@ export const updateTicketAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}.json`,
+ url: `${getZendeskBaseUrl(authentication)}/tickets/${ticket_id}.json`,
method: HttpMethod.PUT,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
ticket,
},
diff --git a/packages/pieces/community/zendesk/src/lib/actions/update-user.ts b/packages/pieces/community/zendesk/src/lib/actions/update-user.ts
index a0f6eff177c..e04174631fa 100644
--- a/packages/pieces/community/zendesk/src/lib/actions/update-user.ts
+++ b/packages/pieces/community/zendesk/src/lib/actions/update-user.ts
@@ -3,11 +3,11 @@ import {
Property,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
import { userFieldsDynamicProp } from '../common/props';
export const updateUserAction = createAction({
@@ -96,16 +96,12 @@ export const updateUserAction = createAction({
try {
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/users/${user_id}.json`,
+ url: `${getZendeskBaseUrl(authentication)}/users/${user_id}.json`,
method: HttpMethod.PUT,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
user,
},
diff --git a/packages/pieces/community/zendesk/src/lib/auth.ts b/packages/pieces/community/zendesk/src/lib/auth.ts
new file mode 100644
index 00000000000..7c683f58751
--- /dev/null
+++ b/packages/pieces/community/zendesk/src/lib/auth.ts
@@ -0,0 +1,62 @@
+import { PieceAuth, Property } from '@activepieces/pieces-framework';
+
+const customAuthMarkdown = `
+**Organization**: The organization name can be found in the URL (e.g https://ORGANIZATION_NAME.zendesk.com).
+
+**Agent Email**: The email you use to log in to Zendesk.
+
+**API Token**: You can find this in the Zendesk Admin Panel under Settings > APIs > Zendesk API.
+
+Zendesk is retiring API tokens — see [Zendesk's migration timeline](https://developer.zendesk.com/documentation/authentication/oauth-migration/#migration-timeline). Consider using the OAuth2 connection type instead.
+`;
+
+export const zendeskCustomAuth = PieceAuth.CustomAuth({
+ displayName: 'API Token',
+ description: customAuthMarkdown,
+ props: {
+ email: Property.ShortText({
+ displayName: 'Agent Email',
+ description: 'The email address you use to login to Zendesk',
+ required: true,
+ }),
+ token: Property.ShortText({
+ displayName: 'Token',
+ description: 'The API token you can generate in Zendesk',
+ required: true,
+ }),
+ subdomain: Property.ShortText({
+ displayName: 'Organization (e.g activepieceshelp)',
+ description: 'The subdomain of your Zendesk instance',
+ required: true,
+ }),
+ },
+ required: true,
+});
+
+const oauth2Markdown = `
+To connect with OAuth2, create an OAuth client in your Zendesk account:
+
+1. Go to **Admin Center > Apps and integrations > APIs > OAuth clients**.
+2. Click **Add OAuth client**, give it a name, and set **Client kind** to **Confidential**.
+3. Set **Redirect URL** to the redirect URL shown below.
+4. Save, then copy the generated **Client ID** and **Secret** into the fields below.
+`;
+
+export const zendeskOAuth2Auth = PieceAuth.OAuth2({
+ description: oauth2Markdown,
+ props: {
+ subdomain: Property.ShortText({
+ displayName: 'Organization (e.g activepieceshelp)',
+ description: 'The organization name can be found in the URL (e.g https://ORGANIZATION_NAME.zendesk.com).',
+ required: true,
+ }),
+ },
+ authUrl: 'https://{subdomain}.zendesk.com/oauth/authorizations/new',
+ tokenUrl: 'https://{subdomain}.zendesk.com/oauth/tokens',
+ scope: ['read', 'write'],
+ pkce: true,
+ pkceMethod: 'S256',
+ required: true,
+});
+
+export const zendeskAuth = [zendeskCustomAuth, zendeskOAuth2Auth];
diff --git a/packages/pieces/community/zendesk/src/lib/common/client.ts b/packages/pieces/community/zendesk/src/lib/common/client.ts
new file mode 100644
index 00000000000..1b9c13be229
--- /dev/null
+++ b/packages/pieces/community/zendesk/src/lib/common/client.ts
@@ -0,0 +1,63 @@
+import { AppConnectionType, AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
+import { AuthenticationType } from '@activepieces/pieces-common';
+import type { zendeskAuth } from '../auth';
+
+export function getZendeskSubdomain(auth: ZendeskAuthValue): string {
+ const value = auth as ZendeskAuth;
+ if (isCustomAuth(value)) {
+ return value.props.subdomain;
+ }
+ return value.props?.subdomain ?? '';
+}
+
+export function getZendeskBaseUrl(auth: ZendeskAuthValue): string {
+ return `https://${getZendeskSubdomain(auth)}.zendesk.com/api/v2`;
+}
+
+export function getZendeskAuthentication(auth: ZendeskAuthValue) {
+ const value = auth as ZendeskAuth;
+ if (isCustomAuth(value)) {
+ return {
+ type: AuthenticationType.BASIC,
+ username: `${value.props.email}/token`,
+ password: value.props.token,
+ } as const;
+ }
+ return {
+ type: AuthenticationType.BEARER_TOKEN,
+ token: value.access_token,
+ } as const;
+}
+
+export function getZendeskAuthorizationHeader(auth: ZendeskAuthValue): string {
+ const value = auth as ZendeskAuth;
+ if (isCustomAuth(value)) {
+ return `Basic ${Buffer.from(`${value.props.email}/token:${value.props.token}`).toString('base64')}`;
+ }
+ return `Bearer ${value.access_token}`;
+}
+
+function isCustomAuth(auth: ZendeskAuth): auth is ZendeskCustomAuthValue {
+ return auth.type === AppConnectionType.CUSTOM_AUTH;
+}
+
+type ZendeskCustomAuthValue = {
+ type: AppConnectionType.CUSTOM_AUTH;
+ props: {
+ email: string;
+ token: string;
+ subdomain: string;
+ };
+};
+
+type ZendeskOAuth2AuthValue = {
+ type: AppConnectionType.OAUTH2 | AppConnectionType.CLOUD_OAUTH2 | AppConnectionType.PLATFORM_OAUTH2;
+ access_token: string;
+ props?: {
+ subdomain: string;
+ };
+};
+
+type ZendeskAuth = ZendeskCustomAuthValue | ZendeskOAuth2AuthValue;
+
+export type ZendeskAuthValue = AppConnectionValueForAuthProperty<typeof zendeskAuth>;
diff --git a/packages/pieces/community/zendesk/src/lib/common/props.ts b/packages/pieces/community/zendesk/src/lib/common/props.ts
index 81e7c733b6a..9f82e4d3895 100644
--- a/packages/pieces/community/zendesk/src/lib/common/props.ts
+++ b/packages/pieces/community/zendesk/src/lib/common/props.ts
@@ -1,10 +1,7 @@
import { DynamicPropsValue, Property } from '@activepieces/pieces-framework';
-import {
- HttpMethod,
- AuthenticationType,
- httpClient,
-} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { HttpMethod, httpClient } from '@activepieces/pieces-common';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from './client';
interface ZendeskTicket {
id: number;
@@ -103,15 +100,10 @@ export const ticketIdDropdown = Property.Dropdown({
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskTicketsResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets.json?per_page=100`,
+ url: `${getZendeskBaseUrl(auth)}/tickets.json?per_page=100`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const tickets = response.body.tickets;
@@ -155,16 +147,11 @@ auth: zendeskAuth,
}
try {
- const authentication = auth;
const response =
await httpClient.sendRequest<ZendeskOrganizationsResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organizations.json?per_page=100`,
+ url: `${getZendeskBaseUrl(auth)}/organizations.json?per_page=100`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const organizations = response.body.organizations;
@@ -210,15 +197,10 @@ auth: zendeskAuth,
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskUsersResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/users.json?per_page=100`,
+ url: `${getZendeskBaseUrl(auth)}/users.json?per_page=100`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const users = response.body.users;
@@ -264,15 +246,10 @@ auth: zendeskAuth,
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskBrandsResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/brands.json`,
+ url: `${getZendeskBaseUrl(auth)}/brands.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const brands = response.body.brands;
@@ -320,15 +297,10 @@ auth: zendeskAuth,
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskTicketsResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/tickets.json?per_page=100`,
+ url: `${getZendeskBaseUrl(auth)}/tickets.json?per_page=100`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const tickets = response.body.tickets;
@@ -378,15 +350,10 @@ auth: zendeskAuth,
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskCustomRolesResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/custom_roles.json`,
+ url: `${getZendeskBaseUrl(auth)}/custom_roles.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const customRoles = response.body.custom_roles;
@@ -429,15 +396,10 @@ export const agentBrandIdDropdown = Property.MultiSelectDropdown({
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskBrandsResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/brands.json`,
+ url: `${getZendeskBaseUrl(auth)}/brands.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const brands = response.body.brands;
@@ -475,15 +437,10 @@ export const userFieldsDynamicProp = Property.DynamicProperties({
if (!auth) return {};
try {
- const authentication = auth;
const response = await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/user_fields.json`,
+ url: `${getZendeskBaseUrl(auth)}/user_fields.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const fields = (response.body as {
@@ -611,15 +568,10 @@ auth: zendeskAuth,
}
try {
- const authentication = auth;
const response = await httpClient.sendRequest<ZendeskGroupsResponse>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/groups.json?per_page=100`,
+ url: `${getZendeskBaseUrl(auth)}/groups.json?per_page=100`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
const groups = response.body.groups;
@@ -644,4 +596,3 @@ auth: zendeskAuth,
}
},
});
-
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-action-on-ticket.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-action-on-ticket.ts
index 03a06cd77cc..acd44cd9c35 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-action-on-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-action-on-ticket.ts
@@ -4,11 +4,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_ticket_action_webhook';
@@ -121,16 +121,12 @@ export const newActionOnTicket = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces Ticket Action Webhook - ${Date.now()}`,
@@ -156,13 +152,9 @@ export const newActionOnTicket = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-group.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-group.ts
index a1cee498086..aa61ae0d4b7 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-group.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-group.ts
@@ -4,14 +4,14 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
DedupeStrategy,
HttpMethod,
httpClient,
Polling,
pollingHelper,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
interface ZendeskGroup {
id: number;
@@ -28,7 +28,7 @@ type ZendeskAuthValue = AppConnectionValueForAuthProperty<typeof zendeskAuth>;
const polling: Polling<ZendeskAuthValue, Record<string, never>> = {
strategy: DedupeStrategy.TIMEBASED,
items: async ({ auth }) => {
- let url: string | undefined = `https://${auth.props.subdomain}.zendesk.com/api/v2/groups?sort=-created_at`;
+ let url: string | undefined = `${getZendeskBaseUrl(auth)}/groups?sort=-created_at`;
const groups: ZendeskGroup[] = [];
while (url) {
@@ -36,11 +36,7 @@ const polling: Polling<ZendeskAuthValue, Record<string, never>> = {
const response = await httpClient.sendRequest<{ groups: ZendeskGroup[]; next_page?: string }>({
url: currentUrl,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: auth.props.email + '/token',
- password: auth.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
groups.push(...response.body.groups);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-organization.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-organization.ts
index 03f7412e61d..dadd4352cf6 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-organization.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-organization.ts
@@ -3,11 +3,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_new_organization_webhook';
@@ -63,16 +63,12 @@ export const newOrganization = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces New Organization Webhook - ${Date.now()}`,
@@ -98,13 +94,9 @@ export const newOrganization = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-suspended-ticket.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-suspended-ticket.ts
index 8761c073d8a..cc93861e178 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-suspended-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-suspended-ticket.ts
@@ -4,11 +4,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_suspended_ticket_webhook';
@@ -112,16 +112,12 @@ export const newSuspendedTicket = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces Suspended Ticket Webhook - ${Date.now()}`,
@@ -147,13 +143,9 @@ export const newSuspendedTicket = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-ticket-in-view.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-ticket-in-view.ts
index fa278548bc5..108b0f83bbe 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-ticket-in-view.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-ticket-in-view.ts
@@ -5,14 +5,14 @@ import {
AppConnectionValueForAuthProperty,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
DedupeStrategy,
httpClient,
HttpMethod,
Polling,
pollingHelper,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
export const newTicketInView = createTrigger({
auth: zendeskAuth,
@@ -43,13 +43,9 @@ export const newTicketInView = createTrigger({
};
}
const response = await httpClient.sendRequest<{ views: any[] }>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/views.json`,
+ url: `${getZendeskBaseUrl(auth)}/views.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
return {
placeholder: 'Select a view',
@@ -154,15 +150,10 @@ const polling: Polling<AppConnectionValueForAuthProperty<typeof zendeskAuth>, {
};
async function getTickets(authentication: AppConnectionValueForAuthProperty<typeof zendeskAuth>, view_id: string) {
- const { email, token, subdomain } = authentication.props;
const response = await httpClient.sendRequest<{ tickets: any[] }>({
- url: `https://${subdomain}.zendesk.com/api/v2/views/${view_id}/tickets.json?sort_order=desc&sort_by=created_at&per_page=200`,
+ url: `${getZendeskBaseUrl(authentication)}/views/${view_id}/tickets.json?sort_order=desc&sort_by=created_at&per_page=200`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: email + '/token',
- password: token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
return response.body.tickets;
}
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-ticket.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-ticket.ts
index d86941c8f6f..631a4196b32 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-ticket.ts
@@ -4,11 +4,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_new_ticket_webhook';
@@ -51,13 +51,9 @@ export const newTicket = createTrigger({
}
try {
const response = await httpClient.sendRequest<{ organizations: ZendeskOrganization[] }>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organizations.json`,
+ url: `${getZendeskBaseUrl(auth)}/organizations.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
return {
placeholder: 'Select an organization (optional)',
@@ -134,16 +130,12 @@ export const newTicket = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces New Ticket Webhook - ${Date.now()}`,
@@ -169,13 +161,9 @@ export const newTicket = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/new-user.ts b/packages/pieces/community/zendesk/src/lib/trigger/new-user.ts
index 937ee636c6c..1d71700ae6a 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/new-user.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/new-user.ts
@@ -4,11 +4,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_new_user_webhook';
@@ -123,16 +123,12 @@ export const newUser = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces New User Webhook - ${Date.now()}`,
@@ -158,13 +154,9 @@ export const newUser = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-ticket.ts b/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-ticket.ts
index 7afdd536554..7d93c82a566 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-ticket.ts
@@ -4,11 +4,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_tag_added_webhook';
@@ -112,16 +112,12 @@ export const tagAddedToTicket = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces Tag Added Webhook - ${Date.now()}`,
@@ -147,13 +143,9 @@ export const tagAddedToTicket = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-user.ts b/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-user.ts
index 70fd1d43eff..eec8a07fc1f 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-user.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/tag-added-to-user.ts
@@ -3,11 +3,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_tag_added_to_user_webhook';
@@ -85,16 +85,12 @@ export const tagAddedToUser = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces Tag Added to User Webhook - ${Date.now()}`,
@@ -120,13 +116,9 @@ export const tagAddedToUser = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
await context.store.delete(WEBHOOK_TRIGGER_KEY);
} catch (error) {
diff --git a/packages/pieces/community/zendesk/src/lib/trigger/updated-ticket.ts b/packages/pieces/community/zendesk/src/lib/trigger/updated-ticket.ts
index 114d77d5da7..e4ac1d077c5 100644
--- a/packages/pieces/community/zendesk/src/lib/trigger/updated-ticket.ts
+++ b/packages/pieces/community/zendesk/src/lib/trigger/updated-ticket.ts
@@ -4,11 +4,11 @@ import {
TriggerStrategy,
} from '@activepieces/pieces-framework';
import {
- AuthenticationType,
HttpMethod,
httpClient,
} from '@activepieces/pieces-common';
-import { zendeskAuth } from '../..';
+import { zendeskAuth } from '../auth';
+import { getZendeskAuthentication, getZendeskBaseUrl } from '../common/client';
const WEBHOOK_TRIGGER_KEY = 'zendesk_updated_ticket_webhook';
@@ -58,13 +58,9 @@ export const updatedTicket = createTrigger({
}
try {
const response = await httpClient.sendRequest<{ organizations: ZendeskOrganization[] }>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/organizations.json`,
+ url: `${getZendeskBaseUrl(auth)}/organizations.json`,
method: HttpMethod.GET,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(auth),
});
return {
placeholder: 'Select an organization (optional)',
@@ -156,16 +152,12 @@ export const updatedTicket = createTrigger({
const response = await httpClient.sendRequest<{
webhook: { id: string };
}>({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks`,
method: HttpMethod.POST,
headers: {
'Content-Type': 'application/json',
},
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
body: {
webhook: {
name: `Activepieces Updated Ticket Webhook - ${Date.now()}`,
@@ -191,13 +183,9 @@ export const updatedTicket = createTrigger({
if (webhookId) {
try {
await httpClient.sendRequest({
- url: `https://${authentication.props.subdomain}.zendesk.com/api/v2/webhooks/${webhookId}`,
+ url: `${getZendeskBaseUrl(authentication)}/webhooks/${webhookId}`,
method: HttpMethod.DELETE,
- authentication: {
- type: AuthenticationType.BASIC,
- username: authentication.props.email + '/token',
- password: authentication.props.token,
- },
+ authentication: getZendeskAuthentication(authentication),
});
} catch (error) {
console.warn(`Warning: Failed to delete webhook ${webhookId}:`, (error as Error).message);
diff --git a/packages/pieces/community/zendesk/test/client.test.ts b/packages/pieces/community/zendesk/test/client.test.ts
new file mode 100644
index 00000000000..9cd3cfcba15
--- /dev/null
+++ b/packages/pieces/community/zendesk/test/client.test.ts
@@ -0,0 +1,72 @@
+import { describe, expect, it } from 'vitest';
+import { AppConnectionType } from '@activepieces/pieces-framework';
+import { AuthenticationType } from '@activepieces/pieces-common';
+import {
+ getZendeskAuthentication,
+ getZendeskAuthorizationHeader,
+ getZendeskBaseUrl,
+ getZendeskSubdomain,
+ ZendeskAuthValue,
+} from '../src/lib/common/client';
+
+const customAuth = {
+ type: AppConnectionType.CUSTOM_AUTH,
+ props: {
+ email: '[email protected]',
+ token: 'my-api-token',
+ subdomain: 'activepieceshelp',
+ },
+} as unknown as ZendeskAuthValue;
+
+const oauth2Auth = {
+ type: AppConnectionType.OAUTH2,
+ access_token: 'my-access-token',
+ props: {
+ subdomain: 'activepieceshelp',
+ },
+} as unknown as ZendeskAuthValue;
+
+describe('getZendeskSubdomain', () => {
+ it('reads the subdomain from a CustomAuth connection', () => {
+ expect(getZendeskSubdomain(customAuth)).toBe('activepieceshelp');
+ });
+
+ it('reads the subdomain from an OAuth2 connection', () => {
+ expect(getZendeskSubdomain(oauth2Auth)).toBe('activepieceshelp');
+ });
+});
+
+describe('getZendeskBaseUrl', () => {
+ it('builds the API v2 base URL from the connection subdomain', () => {
+ expect(getZendeskBaseUrl(customAuth)).toBe('https://activepieceshelp.zendesk.com/api/v2');
+ expect(getZendeskBaseUrl(oauth2Auth)).toBe('https://activepieceshelp.zendesk.com/api/v2');
+ });
+});
+
+describe('getZendeskAuthentication', () => {
+ it('returns a Basic authentication object for CustomAuth', () => {
+ expect(getZendeskAuthentication(customAuth)).toEqual({
+ type: AuthenticationType.BASIC,
+ username: '[email protected]/token',
+ password: 'my-api-token',
+ });
+ });
+
+ it('returns a Bearer token authentication object for OAuth2', () => {
+ expect(getZendeskAuthentication(oauth2Auth)).toEqual({
+ type: AuthenticationType.BEARER_TOKEN,
+ token: 'my-access-token',
+ });
+ });
+});
+
+describe('getZendeskAuthorizationHeader', () => {
+ it('returns a base64 Basic header for CustomAuth', () => {
+ const expected = `Basic ${Buffer.from('[email protected]/token:my-api-token').toString('base64')}`;
+ expect(getZendeskAuthorizationHeader(customAuth)).toBe(expected);
+ });
+
+ it('returns a Bearer header for OAuth2', () => {
+ expect(getZendeskAuthorizationHeader(oauth2Auth)).toBe('Bearer my-access-token');
+ });
+});
diff --git a/packages/pieces/community/zendesk/vitest.config.ts b/packages/pieces/community/zendesk/vitest.config.ts
new file mode 100644
index 00000000000..ba8ade4a178
--- /dev/null
+++ b/packages/pieces/community/zendesk/vitest.config.ts
@@ -0,0 +1,17 @@
+import path from 'path'
+import { defineConfig } from 'vitest/config'
+
+const repoRoot = path.resolve(__dirname, '../../../..')
+
+export default defineConfig({
+ test: {
+ globals: true,
+ environment: 'node',
+ },
+ resolve: {
+ alias: {
+ '@activepieces/pieces-framework': path.resolve(repoRoot, 'packages/pieces/framework/src/index.ts'),
+ '@activepieces/pieces-common': path.resolve(repoRoot, 'packages/pieces/common/src/index.ts'),
+ },
+ },
+})