diff --git a/README.md b/README.md index 304ba70..fc7ae8b 100644 --- a/README.md +++ b/README.md @@ -433,6 +433,18 @@ api.getAttributes("1", IdentifierType.ID); - **id**: Customer identifier, String or number (required) - **id_type**: One of the ID types - "id" / "email" / "cio_id" (default is "id") +### api.getAttributesBatch(ids) + +Returns a list of attributes and devices for up to 100 customer profiles. + +```javascript +api.getAttributesBatch(["1", "2", "3"]); +``` + +#### Options + +- **ids**: Customer identifiers, array of String (required) + ### api.listExports() Return a list of your exports. Exports are point-in-time people or campaign metrics. diff --git a/lib/api.ts b/lib/api.ts index 1c6e8bf..8a7afcf 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -158,6 +158,22 @@ export class APIClient { return this.request.get(`${this.apiRoot}/customers/${id}/attributes?id_type=${idType}`); } + + getAttributesBatch(ids: string[]) { + if (isEmpty(ids)) { + throw new MissingParamError('ids'); + } + + if (!Array.isArray(ids)) { + throw new Error('ids must be an array'); + } + + if (ids.length > 100) { + throw new Error('Maximum of 100 customer IDs allowed'); + } + + return this.request.post(`${this.apiRoot}/customers/attributes`, { ids }); + } } export { SendEmailRequest, SendPushRequest } from './api/requests'; diff --git a/test/api.ts b/test/api.ts index 787201d..d93282b 100644 --- a/test/api.ts +++ b/test/api.ts @@ -499,3 +499,33 @@ test('#getAttributes: success with type email', (t) => { ), ); }); + +test('#getAttributesBatch: fails without customerId', (t) => { + sinon.stub(t.context.client.request, 'post'); + t.throws(() => (t.context.client.getAttributesBatch as any)(), { + message: 'ids is required', + }); + t.falsy((t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/attributes`)); +}); + +test('#getAttributesBatch: fails if ids is not array', (t) => { + sinon.stub(t.context.client.request, 'post'); + t.throws(() => (t.context.client.getAttributesBatch as any)(1), { + message: 'ids must be an array', + }); + t.falsy((t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/attributes`)); +}); + +test('#getAttributesBatch: fails if length of ids is greater than 100', (t) => { + sinon.stub(t.context.client.request, 'post'); + t.throws(() => (t.context.client.getAttributesBatch as any)(Array(101).fill(1)), { + message: 'Maximum of 100 customer IDs allowed', + }); + t.falsy((t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/attributes`)); +}); + +test('#getAttributesBatch: success with default type id', (t) => { + sinon.stub(t.context.client.request, 'post'); + t.context.client.getAttributesBatch(['1']); + t.truthy((t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/attributes`)); +});