@@ -14,7 +14,8 @@ import {
1414 ICustomObjectRecordField ,
1515 ISearchCustomObjectRecordsFilter ,
1616 IBulkJobResponse ,
17- IBulkJobBody
17+ IBulkJobBody ,
18+ ISearchFilterCustomObjectRecords
1819} from "@models/index" ;
1920import { Client } from "@zendesk/sell-zaf-app-toolbox" ;
2021
@@ -235,6 +236,56 @@ export class CustomObjectService {
235236 } as ISearchCustomObjectRecordsFilter ) ;
236237 }
237238
239+ /**
240+ * Filter custom object records using advanced search criteria
241+ *
242+ * This method performs a filtered search of custom object records using POST request with complex filter conditions.
243+ * Filters can contain individual comparison objects or arrays of comparison objects within logical namespaces ($and, $or).
244+ *
245+ * @param key - The custom object key identifier
246+ * @param filter - The search filter object containing comparison conditions
247+ * @param filter.filter - A JSON object with the following properties:
248+ * - ATTRIBUTE: A comparison object specifying an attribute value condition
249+ * - $and: Array of conjunctive filter objects (logical AND)
250+ * - $or: Array of disjunctive filter objects (logical OR)
251+ *
252+ * @returns Promise that resolves to an array of custom object records matching the filter criteria
253+ *
254+ * @example
255+ * ```typescript
256+ * // Simple attribute filter
257+ * const records = await service.filterRecords('my_object', {
258+ * filter: {
259+ * "custom_object_fields.field_key": { "$eq": "value" }
260+ * }
261+ * });
262+ *
263+ * // Using logical OR
264+ * const records = await service.filterRecords('my_object', {
265+ * filter: {
266+ * "$or": [
267+ * { "custom_object_fields.field_key": { "$eq": "value" } },
268+ * { "external_id": { "$eq": "Record123" } }
269+ * ]
270+ * }
271+ * });
272+ * ```
273+ *
274+ * @remarks
275+ * - Custom fields must be namespaced with `custom_object_fields.` (e.g., `custom_object_fields.field_key`)
276+ * - Standard fields (created_at, updated_at, created_by_user, updated_by_user, name, external_id) require no namespace
277+ * - Supported operators vary by the value's data type
278+ * - This method uses pagination internally to fetch all matching records
279+ *
280+ * @see {@link https://developer.zendesk.com/api-reference/custom-data/custom-objects/custom_object_records/#filtered-search-of-custom-object-records | Zendesk API Documentation }
281+ */
282+ public async filterRecords < T extends ICustomObjectRecordField > (
283+ key : string ,
284+ filter : ISearchFilterCustomObjectRecords
285+ ) : Promise < ICustomObjectRecord < T > [ ] > {
286+ return this . fetchAllPaginatedRecords < T > ( `/api/v2/custom_objects/${ key } /records/search` , filter , "POST" ) ;
287+ }
288+
238289 /**
239290 * Bulk create or update custom object records
240291 * This endpoint allows you to create or update multiple custom object records in a single request.
@@ -263,25 +314,40 @@ export class CustomObjectService {
263314 */
264315 private async fetchAllPaginatedRecords < T extends ICustomObjectRecordField > (
265316 url : string ,
266- initialData : IListFilter
317+ initialData : IListFilter | ISearchFilterCustomObjectRecords ,
318+ method : "GET" | "POST" | "PATCH" | "DELETE" = "GET"
267319 ) : Promise < ICustomObjectRecord < T > [ ] > {
268320 let hasMore = true ;
269- let data = initialData ;
321+ let d = initialData ;
270322 let objects : ICustomObjectRecord < T > [ ] = [ ] ;
271323
272324 do {
273- const response = await this . client . request < any , IListCustomObjectRecordsResponse < T > > ( {
325+ let options : {
326+ url : string ;
327+ type : "GET" | "POST" | "PATCH" | "DELETE" ;
328+ contentType : string ;
329+ data ?: unknown ;
330+ } = {
274331 url,
275- type : "GET" ,
332+ type : method ,
276333 contentType : CONTENT_TYPE ,
277- data
278- } ) ;
334+ data : d
335+ } ;
336+
337+ if ( method === "POST" ) {
338+ options = {
339+ ...options ,
340+ data : JSON . stringify ( d )
341+ } ;
342+ }
343+
344+ const response = await this . client . request < any , IListCustomObjectRecordsResponse < T > > ( options ) ;
279345
280346 objects = [ ...objects , ...response . custom_object_records ] ;
281347
282348 hasMore = response . meta . has_more ;
283349 if ( hasMore ) {
284- data = {
350+ d = {
285351 page : {
286352 after : response . meta . after_cursor
287353 } ,
0 commit comments