Skip to content

Commit beb4b06

Browse files
committed
fix(zoho-desk): reject an empty update_ticket PATCH with a clear error
update_ticket built its PATCH body from optional fields via filterUndefined, so a call with no fields set sent `{}` and surfaced an opaque Zoho failure. Guard the body builder to throw an actionable "provide at least one field" error before the request. Adds a test for the empty and populated body paths.
1 parent 9b18ea6 commit beb4b06

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { zohoDeskUpdateTicketTool } from '@/tools/zoho_desk/update_ticket'
6+
7+
describe('zohoDeskUpdateTicketTool request body', () => {
8+
const base = { accessToken: 'tok', orgId: '700', ticketId: '123' }
9+
const buildBody = zohoDeskUpdateTicketTool.request.body as (p: Record<string, unknown>) => unknown
10+
11+
it('throws when no updatable fields are provided', () => {
12+
expect(() => buildBody(base)).toThrow(/no fields to update/i)
13+
})
14+
15+
it('builds a body containing only the provided fields', () => {
16+
expect(buildBody({ ...base, status: 'Closed' })).toEqual({ status: 'Closed' })
17+
expect(buildBody({ ...base, priority: 'High', subject: 'Hi' })).toEqual({
18+
priority: 'High',
19+
subject: 'Hi',
20+
})
21+
})
22+
})

apps/sim/tools/zoho_desk/update_ticket.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export const zohoDeskUpdateTicketTool: ToolConfig<ZohoDeskUpdateTicketParams, Zo
101101
url: (params) => `${getZohoDeskApiBase(params)}/tickets/${encodeURIComponent(params.ticketId)}`,
102102
method: 'PATCH',
103103
headers: (params) => buildZohoDeskHeaders(params),
104-
body: (params) =>
105-
filterUndefined({
104+
body: (params) => {
105+
const body = filterUndefined({
106106
subject: params.subject,
107107
status: params.status,
108108
priority: params.priority,
@@ -112,7 +112,16 @@ export const zohoDeskUpdateTicketTool: ToolConfig<ZohoDeskUpdateTicketParams, Zo
112112
subCategory: params.subCategory,
113113
dueDate: params.dueDate,
114114
customFields: params.customFields,
115-
}),
115+
})
116+
// Zoho rejects an empty PATCH; fail early with an actionable message
117+
// instead of surfacing an opaque Zoho error for a no-op update.
118+
if (Object.keys(body).length === 0) {
119+
throw new Error(
120+
'No fields to update. Provide at least one field to change (e.g. status, priority, or subject).'
121+
)
122+
}
123+
return body
124+
},
116125
},
117126

118127
transformResponse: async (response) => {

0 commit comments

Comments
 (0)