Skip to content

Commit 42ef262

Browse files
committed
Added mailingLists params
1 parent b5ba99c commit 42ef262

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ Create a new contact.
7272

7373
#### Parameters
7474

75-
| Name | Type | Required | Notes |
76-
| ------------ | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77-
| `email` | string | Yes | If a contact already exists with this email address, an error response will be returned. |
78-
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
75+
| Name | Type | Required | Notes |
76+
| -------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77+
| `email` | string | Yes | If a contact already exists with this email address, an error response will be returned. |
78+
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
79+
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
7980

8081
#### Examples
8182

@@ -86,7 +87,15 @@ const contactProperties = {
8687
firstName: "Bob" /* Default property */,
8788
favoriteColor: "Red" /* Custom property */,
8889
};
89-
const resp = await loops.createContact("[email protected]", contactProperties);
90+
const mailingLists = {
91+
list_123: true,
92+
list_456: false,
93+
};
94+
const resp = await loops.createContact(
95+
96+
contactProperties,
97+
mailingLists
98+
);
9099
```
91100

92101
#### Response
@@ -119,10 +128,11 @@ Note: To update a contact's email address, the contact requires a `userId` value
119128

120129
#### Parameters
121130

122-
| Name | Type | Required | Notes |
123-
| ------------ | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
124-
| `email` | string | Yes | The email address of the contact to update. If there is no contact with this email address, a new contact will be created using the email and properties in this request. |
125-
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
131+
| Name | Type | Required | Notes |
132+
| -------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133+
| `email` | string | Yes | The email address of the contact to update. If there is no contact with this email address, a new contact will be created using the email and properties in this request. |
134+
| `properties` | object | No | An object containing default and any custom properties for your contact.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
135+
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
126136

127137
#### Example
128138

@@ -301,6 +311,7 @@ Send an event to trigger an email in Loops. [Read more about events](https://loo
301311
| `eventName` | string | Yes | |
302312
| `contactProperties` | object | No | An object containing contact properties, which will be updated or added to the contact when the event is received.<br />Please [add custom properties](https://loops.so/docs/contacts/properties#custom-contact-properties) in your Loops account before using them with the SDK.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/contacts/properties#dates)). |
303313
| `eventProperties` | object | No | An object containing event properties, which will be made availabe in emails that are triggered by this event.<br />Values can be of type `string`, `number`, `boolean` or `date` ([see allowed date formats](https://loops.so/docs/events/properties#important-information-about-event-properties)). |
314+
| `mailingLists` | object | No | An object of mailing list IDs and boolean subscription statuses. |
304315

305316
#### Examples
306317

@@ -317,6 +328,10 @@ const resp = await loops.sendEvent({
317328
username: "user1234",
318329
signupDate: "2024-03-21T10:09:23Z",
319330
},
331+
mailingLists: {
332+
"list_123": true,
333+
"list_456": false
334+
}
320335
});
321336

322337
// In this case with both email and userId present, the system will look for a contact with either a

src/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,18 @@ class LoopsClient {
163163
*
164164
* @param {string} email The email address of the contact.
165165
* @param {Object} [properties] All other contact properties, including custom properties.
166+
* @param {Object} [mailingLists] An object of mailing list IDs and boolean subscription statuses.
166167
*
167168
* @see https://loops.so/docs/api-reference/create-contact
168169
*
169170
* @returns {Object} Contact record or error response (JSON)
170171
*/
171172
async createContact(
172173
email: string,
173-
properties?: ContactProperties
174+
properties?: ContactProperties,
175+
mailingLists?: Record<string, boolean>
174176
): Promise<ContactSuccessResponse | ErrorResponse> {
175-
const payload = { email, ...properties };
177+
const payload = { email, ...properties, mailingLists };
176178
return this._makeQuery({
177179
path: "v1/contacts/create",
178180
method: "POST",
@@ -185,16 +187,18 @@ class LoopsClient {
185187
*
186188
* @param {string} email The email address of the contact.
187189
* @param {Object} properties All other contact properties, including custom properties.
190+
* @param {Object} [mailingLists] An object of mailing list IDs and boolean subscription statuses.
188191
*
189192
* @see https://loops.so/docs/api-reference/update-contact
190193
*
191194
* @returns {Object} Contact record or error response (JSON)
192195
*/
193196
async updateContact(
194197
email: string,
195-
properties: ContactProperties
198+
properties: ContactProperties,
199+
mailingLists?: Record<string, boolean>
196200
): Promise<ContactSuccessResponse | ErrorResponse> {
197-
const payload = { email, ...properties };
201+
const payload = { email, ...properties, mailingLists };
198202
return this._makeQuery({
199203
path: "v1/contacts/update",
200204
method: "PUT",
@@ -283,6 +287,7 @@ class LoopsClient {
283287
* @param {string} params.eventName The name of the event.
284288
* @param {Object} [params.contactProperties] Properties to update the contact with, including custom properties.
285289
* @param {Object} [params.eventProperties] Event properties, made available in emails triggered by the event.
290+
* @param {Object} [params.mailingLists] An object of mailing list IDs and boolean subscription statuses.
286291
*
287292
* @see https://loops.so/docs/api-reference/send-event
288293
*
@@ -294,12 +299,14 @@ class LoopsClient {
294299
eventName,
295300
contactProperties,
296301
eventProperties,
302+
mailingLists,
297303
}: {
298304
email?: string;
299305
userId?: string;
300306
eventName: string;
301307
contactProperties?: ContactProperties;
302308
eventProperties?: EventProperties;
309+
mailingLists?: Record<string, boolean>;
303310
}): Promise<EventResponse> {
304311
if (!userId && !email)
305312
throw "You must provide an `email` or `userId` value.";
@@ -308,10 +315,12 @@ class LoopsClient {
308315
userId?: string;
309316
eventName: string;
310317
eventProperties?: EventProperties;
318+
mailingLists?: Record<string, boolean>;
311319
} = {
312320
eventName,
313321
...contactProperties,
314322
eventProperties,
323+
mailingLists,
315324
};
316325
if (email) payload["email"] = email;
317326
if (userId) payload["userId"] = userId;

0 commit comments

Comments
 (0)