Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
30 changes: 30 additions & 0 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`));
});