Skip to content

Commit

Permalink
add filter custom objects function
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Romolini <paolo.romolini@enterprisedb.com>
  • Loading branch information
paoloromolini committed Aug 13, 2024
1 parent 722b6cc commit 6869945
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
31 changes: 31 additions & 0 deletions zendesk/custom_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type CustomObjectAPI interface {
ctx context.Context,
customObjectKey string,
) ([]CustomObjectField, error)
FilterCustomObjectRecords(
ctx context.Context, customObjectKey string, filterBody interface{}, opts *CursorPagination,
) ([]CustomObjectRecord, CursorPaginationMeta, error)
}

// CreateCustomObjectRecord CreateCustomObject create a custom object record
Expand Down Expand Up @@ -319,3 +322,31 @@ func (z *Client) ListCustomObjectFields(
}
return result.CustomObjectFields, nil
}

// FilterCustomObjectRecords
// https://developer.zendesk.com/api-reference/custom-data/custom-objects/
// custom_object_records/#filtered-search-of-custom-object-records
func (z *Client) FilterCustomObjectRecords(
ctx context.Context, customObjectKey string, filterBody interface{}, opts *CursorPagination,
) ([]CustomObjectRecord, CursorPaginationMeta, error) {
var data struct {
FilterBody interface{} `json:"filter"`
}

var result struct {
CustomObjectRecords []CustomObjectRecord `json:"custom_object_records"`
Meta CursorPaginationMeta `json:"meta"`
}
tmp := opts
if tmp == nil {
tmp = &CursorPagination{}
}
url := fmt.Sprintf("/custom_objects/%s/records/search", customObjectKey)
urlWithOptions, err := addOptions(url, tmp)
body, err := z.post(ctx, urlWithOptions, data)
if err != nil {
return nil, CursorPaginationMeta{}, err
}
err = json.Unmarshal(body, &result)
return result.CustomObjectRecords, result.Meta, nil
}
92 changes: 92 additions & 0 deletions zendesk/mock/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6869945

Please sign in to comment.