Skip to content

Commit 1ecec35

Browse files
committed
Parameter object for sendTransactionalEmail
1 parent 9fd06a0 commit 1ecec35

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -391,29 +391,29 @@ Send a transactional email to a contact. [Learn about sending transactional emai
391391
#### Examples
392392

393393
```javascript
394-
const dataVariables = {
395-
loginUrl: "https://myapp.com/login/",
396-
};
397-
const resp = await loops.sendTransactionalEmail(
398-
"clfq6dinn000yl70fgwwyp82l",
399-
400-
dataVariables
401-
);
394+
const resp = await loops.sendTransactionalEmail({
395+
transactionalId: "clfq6dinn000yl70fgwwyp82l",
396+
397+
dataVariables: {
398+
loginUrl: "https://myapp.com/login/",
399+
},
400+
});
402401

403402
// Please contact us to enable attachments on your account.
404-
const attachments = [
405-
{
406-
filename: "presentation.pdf",
407-
contentType: "application/pdf",
408-
data: "JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPD...",
403+
const resp = await loops.sendTransactionalEmail({
404+
transactionalId: "clfq6dinn000yl70fgwwyp82l",
405+
406+
dataVariables: {
407+
loginUrl: "https://myapp.com/login/",
409408
},
410-
];
411-
const resp = await loops.sendTransactionalEmail(
412-
"clfq6dinn000yl70fgwwyp82l",
413-
414-
dataVariables,
415-
attachments
416-
);
409+
attachments: [
410+
{
411+
filename: "presentation.pdf",
412+
contentType: "application/pdf",
413+
data: "JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPD...",
414+
},
415+
]
416+
});
417417
```
418418

419419
#### Response
@@ -490,7 +490,8 @@ If your account has no custom fields, an empty list will be returned.
490490

491491
## Version history
492492

493-
- `v2.2.0` (Jul 2, 2024) - Added new `addToAudience` option to [`sendTransactionalEmail()`](#sendtransactionalemail).
493+
- `v3.0.0` (Jul 2, 2024) - [`sendTransactionalEmail()`](#sendtransactionalemail) now accepts an object instead of separate parameters (breaking change).
494+
- `v2.2.0` (Jul 2, 2024) - Deprecated. Added new `addToAudience` option to [`sendTransactionalEmail()`](#sendtransactionalemail).
494495
- `v2.1.1` (Jun 20, 2024) - Added support for mailing lists in [`createContact()`](#createcontact), [`updateContact()`](#updatecontact) and [`sendEvent()`](#sendevent).
495496
- `v2.1.0` (Jun 19, 2024) - Added support for new [List mailing lists](#getmailinglists) endpoint.
496497
- `v2.0.0` (Apr 19, 2024)

src/index.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -334,32 +334,37 @@ class LoopsClient {
334334
/**
335335
* Send a transactional email.
336336
*
337-
* @param {string} transactionalId The ID of the transactional email to send.
338-
* @param {string} email The email address of the recipient.
339-
* @param {boolean} [addToAudience] Create a contact in your audience using the provided email address (if one doesn't already exist).
340-
* @param {Object} [dataVariables] Data variables as defined by the transational email template.
341-
* @param {Object[]} [attachments] File(s) to be sent along with the email message.
337+
* @param {Object} params
338+
* @param {string} params.transactionalId The ID of the transactional email to send.
339+
* @param {string} params.email The email address of the recipient.
340+
* @param {boolean} [params.addToAudience] Create a contact in your audience using the provided email address (if one doesn't already exist).
341+
* @param {Object} [params.dataVariables] Data variables as defined by the transational email template.
342+
* @param {Object[]} [params.attachments] File(s) to be sent along with the email message.
342343
*
343344
* @see https://loops.so/docs/api-reference/send-transactional-email
344345
*
345346
* @returns {Object} Confirmation or error response (JSON)
346347
*/
347-
async sendTransactionalEmail(
348-
transactionalId: string,
349-
email: string,
350-
addToAudience?: boolean,
351-
dataVariables?: TransactionalVariables,
352-
attachments?: Array<TransactionalAttachment>
353-
): Promise<TransactionalResponse> {
354-
const payload: {
355-
transactionalId: string;
356-
email: string;
357-
addToAudience?: boolean;
358-
dataVariables?: TransactionalVariables;
359-
attachments?: Array<TransactionalAttachment>;
360-
} = { transactionalId, email, addToAudience };
361-
if (dataVariables) payload["dataVariables"] = dataVariables;
362-
if (attachments) payload["attachments"] = attachments;
348+
async sendTransactionalEmail({
349+
transactionalId,
350+
email,
351+
addToAudience,
352+
dataVariables,
353+
attachments,
354+
}: {
355+
transactionalId: string;
356+
email: string;
357+
addToAudience?: boolean;
358+
dataVariables?: TransactionalVariables;
359+
attachments?: Array<TransactionalAttachment>;
360+
}): Promise<TransactionalResponse> {
361+
const payload = {
362+
transactionalId,
363+
email,
364+
addToAudience,
365+
dataVariables,
366+
attachments,
367+
};
363368
return this._makeQuery({
364369
path: "v1/transactional",
365370
method: "POST",
@@ -381,4 +386,4 @@ class LoopsClient {
381386
}
382387
}
383388

384-
export { LoopsClient };
389+
export { LoopsClient };

0 commit comments

Comments
 (0)