From 00139ff6f03afa33cf5f3fc1523b924e47f00109 Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Thu, 9 Jul 2026 12:20:17 +0200 Subject: [PATCH 1/2] MT-22678: Add search param to contact lists getList --- README.md | 2 +- examples/contact-lists/everything.ts | 4 ++ src/__tests__/lib/api/ContactLists.test.ts | 58 +++++++++++++++++++ .../lib/api/resources/ContactLists.test.ts | 19 ++++++ src/lib/api/resources/ContactLists.ts | 14 +++-- src/types/api/contactlist.ts | 4 ++ 6 files changed, 96 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 50b54e85..66f60a9f 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ Email Sandbox (Testing): Contact management: - Contacts CRUD & listing – [`contacts/everything.ts`](examples/contacts/everything.ts) -- Contact lists CRUD – [`contact-lists/everything.ts`](examples/contact-lists/everything.ts) +- Contact lists CRUD & search by name – [`contact-lists/everything.ts`](examples/contact-lists/everything.ts) - Custom fields CRUD – [`contact-fields/everything.ts`](examples/contact-fields/everything.ts) - Import/Export – [`contact-imports/everything.ts`](examples/contact-imports/everything.ts), [`contact-exports/everything.ts`](examples/contact-exports/everything.ts) - Events – [`contact-events/everything.ts`](examples/contact-events/everything.ts) diff --git a/examples/contact-lists/everything.ts b/examples/contact-lists/everything.ts index 991edac5..c1cad71b 100644 --- a/examples/contact-lists/everything.ts +++ b/examples/contact-lists/everything.ts @@ -18,6 +18,10 @@ async function contactListsFlow() { const all = await client.contactLists.getList(); console.log("All contact lists:", all); + // Filter contact lists by name (case-insensitive prefix match) + const filtered = await client.contactLists.getList({ search: "news" }); + console.log("Filtered contact lists:", filtered); + // Get a specific contact list const one = await client.contactLists.get(all[0].id); console.log("One contact list:", one); diff --git a/src/__tests__/lib/api/ContactLists.test.ts b/src/__tests__/lib/api/ContactLists.test.ts index 2831c867..28fbc1e8 100644 --- a/src/__tests__/lib/api/ContactLists.test.ts +++ b/src/__tests__/lib/api/ContactLists.test.ts @@ -1,8 +1,17 @@ import axios from "axios"; +import AxiosMockAdapter from "axios-mock-adapter"; import ContactLists from "../../../lib/api/ContactLists"; +import handleSendingError from "../../../lib/axios-logger"; +import { ContactList } from "../../../types/api/contactlist"; + +import CONFIG from "../../../config"; + +const { CLIENT_SETTINGS } = CONFIG; +const { GENERAL_ENDPOINT } = CLIENT_SETTINGS; describe("lib/api/ContactLists: ", () => { + let mock: AxiosMockAdapter; const accountId = 100; const contactListsAPI = new ContactLists(axios, accountId); @@ -17,4 +26,53 @@ describe("lib/api/ContactLists: ", () => { }); }); }); + + beforeAll(() => { + axios.interceptors.response.use( + (response) => response.data, + handleSendingError + ); + mock = new AxiosMockAdapter(axios); + }); + + afterEach(() => { + mock.reset(); + }); + + describe("getList(): ", () => { + it("successfully gets all contact lists.", async () => { + const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/contacts/lists`; + const expectedResponseData: ContactList[] = [ + { id: 1, name: "Test List 1" }, + { id: 2, name: "Test List 2" }, + ]; + + expect.assertions(2); + + mock.onGet(endpoint).reply(200, expectedResponseData); + const result = await contactListsAPI.getList(); + + expect(mock.history.get[0].url).toEqual(endpoint); + expect(result).toEqual(expectedResponseData); + }); + + it("passes the search param to the request.", async () => { + const search = "news"; + const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/contacts/lists`; + const expectedResponseData: ContactList[] = [ + { id: 1, name: "Newsletter" }, + ]; + + expect.assertions(3); + + mock + .onGet(endpoint, { params: { search } }) + .reply(200, expectedResponseData); + const result = await contactListsAPI.getList({ search }); + + expect(mock.history.get[0].url).toEqual(endpoint); + expect(mock.history.get[0].params).toEqual({ search }); + expect(result).toEqual(expectedResponseData); + }); + }); }); diff --git a/src/__tests__/lib/api/resources/ContactLists.test.ts b/src/__tests__/lib/api/resources/ContactLists.test.ts index 3ffa01f1..67f7614d 100644 --- a/src/__tests__/lib/api/resources/ContactLists.test.ts +++ b/src/__tests__/lib/api/resources/ContactLists.test.ts @@ -75,6 +75,25 @@ describe("lib/api/resources/ContactLists: ", () => { expect(result).toEqual(expectedResponseData); }); + it("successfully gets contact lists filtered by name.", async () => { + const search = "news"; + const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/contacts/lists`; + const expectedResponseData: ContactList[] = [ + { id: 1, name: "Newsletter" }, + ]; + + expect.assertions(3); + + mock + .onGet(endpoint, { params: { search } }) + .reply(200, expectedResponseData); + const result = await contactListsAPI.getList({ search }); + + expect(mock.history.get[0].url).toEqual(endpoint); + expect(mock.history.get[0].params).toEqual({ search }); + expect(result).toEqual(expectedResponseData); + }); + it("fails with error.", async () => { const endpoint = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/contacts/lists`; const expectedErrorMessage = "Request failed with status code 400"; diff --git a/src/lib/api/resources/ContactLists.ts b/src/lib/api/resources/ContactLists.ts index 96891448..c45b05a8 100644 --- a/src/lib/api/resources/ContactLists.ts +++ b/src/lib/api/resources/ContactLists.ts @@ -4,6 +4,7 @@ import CONFIG from "../../../config"; import { ContactList, ContactListOptions, + ContactListsListOptions, } from "../../../types/api/contactlist"; const { CLIENT_SETTINGS } = CONFIG; @@ -20,12 +21,17 @@ export default class ContactListsApi { } /** - * Get all contact lists. + * Get all contact lists. Optionally filter by name via a case-insensitive + * prefix match with `search`. */ - public async getList() { - const url = `${this.contactListsURL}`; + public async getList(options?: ContactListsListOptions) { + const params = { + ...(options?.search && { search: options.search }), + }; - return this.client.get(url); + return this.client.get(this.contactListsURL, { + params, + }); } /** diff --git a/src/types/api/contactlist.ts b/src/types/api/contactlist.ts index fa182c17..c71ee215 100644 --- a/src/types/api/contactlist.ts +++ b/src/types/api/contactlist.ts @@ -6,3 +6,7 @@ export interface ContactList { export interface ContactListOptions { name: string; } + +export interface ContactListsListOptions { + search?: string; +} From b566f3faed2c6a11f82dac9bf6542c3e7cc59071 Mon Sep 17 00:00:00 2001 From: Maciej Walusiak Date: Fri, 10 Jul 2026 10:24:07 +0200 Subject: [PATCH 2/2] MT-22678: Drop search filter call-out from README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 66f60a9f..50b54e85 100644 --- a/README.md +++ b/README.md @@ -254,7 +254,7 @@ Email Sandbox (Testing): Contact management: - Contacts CRUD & listing – [`contacts/everything.ts`](examples/contacts/everything.ts) -- Contact lists CRUD & search by name – [`contact-lists/everything.ts`](examples/contact-lists/everything.ts) +- Contact lists CRUD – [`contact-lists/everything.ts`](examples/contact-lists/everything.ts) - Custom fields CRUD – [`contact-fields/everything.ts`](examples/contact-fields/everything.ts) - Import/Export – [`contact-imports/everything.ts`](examples/contact-imports/everything.ts), [`contact-exports/everything.ts`](examples/contact-exports/everything.ts) - Events – [`contact-events/everything.ts`](examples/contact-events/everything.ts)