Skip to content

Commit fd47c66

Browse files
committed
List transactional emails
1 parent b08f473 commit fd47c66

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ You can use custom contact properties in API calls. Please make sure to [add cus
9898
- [getMailingLists()](#getmailinglists)
9999
- [sendEvent()](#sendevent)
100100
- [sendTransactionalEmail()](#sendtransactionalemail)
101+
- [getTransactionalEmails()](#gettransactionalemails)
101102

102103
---
103104

@@ -666,8 +667,71 @@ HTTP 400 Bad Request
666667

667668
---
668669

670+
### getTransactionalEmails()
671+
672+
Get a list of published transactional emails.
673+
674+
[API Reference](https://loops.so/docs/api-reference/list-transactional-emails)
675+
676+
#### Parameters
677+
678+
| Name | Type | Required | Notes |
679+
| --------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
680+
| `perPage` | integer | No | How many results to return per page. Must be between 10 and 50. Defaults to 20 if omitted. |
681+
| `cursor` | string | No | A cursor, to return a specific page of results. Cursors can be found from the `pagination.nextCursor` value in each response. |
682+
683+
#### Example
684+
685+
```javascript
686+
const resp = await loops.getTransactionalEmails();
687+
688+
const resp = await loops.getTransactionalEmails({ perPage: 15 });
689+
```
690+
691+
#### Response
692+
693+
```json
694+
{
695+
"pagination": {
696+
"totalResults": 23,
697+
"returnedResults": 20,
698+
"perPage": 20,
699+
"totalPages": 2,
700+
"nextCursor": "clyo0q4wo01p59fsecyxqsh38",
701+
"nextPage": "https://app.loops.so/api/v1/transactional?cursor=clyo0q4wo01p59fsecyxqsh38&perPage=20"
702+
},
703+
"data": [
704+
{
705+
"id": "clfn0k1yg001imo0fdeqg30i8",
706+
"lastUpdated": "2023-11-06T17:48:07.249Z",
707+
"dataVariables": []
708+
},
709+
{
710+
"id": "cll42l54f20i1la0lfooe3z12",
711+
"lastUpdated": "2025-02-02T02:56:28.845Z",
712+
"dataVariables": [
713+
"confirmationUrl"
714+
]
715+
},
716+
{
717+
"id": "clw6rbuwp01rmeiyndm80155l",
718+
"lastUpdated": "2024-05-14T19:02:52.000Z",
719+
"dataVariables": [
720+
"firstName",
721+
"lastName",
722+
"inviteLink"
723+
]
724+
},
725+
...
726+
]
727+
}
728+
```
729+
730+
---
731+
669732
## Version history
670733

734+
- `v4.1.0` (Feb 27, 2025) - Support for new [List transactional emails](#gettransactionalemails) endpoint.
671735
- `v4.0.0` (Jan 16, 2025)
672736
- Added `APIError` to more easily understand API errors. [See usage example](#usage).
673737
- Added support for two new contact property endpoints: [List contact properties](#listcontactproperties) and [Create contact property](#createcontactproperty).

src/index.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,56 @@ interface MailingList {
147147
isPublic: boolean;
148148
}
149149

150+
interface PaginationData {
151+
/**
152+
* Total results found.
153+
*/
154+
totalResults: number;
155+
/**
156+
* The number of results returned in this response.
157+
*/
158+
returnedResults: number;
159+
/**
160+
* The maximum number of results requested.
161+
*/
162+
perPage: number;
163+
/**
164+
* Total number of pages.
165+
*/
166+
totalPages: number;
167+
/**
168+
* The next cursor (for retrieving the next page of results using the `cursor` parameter), or `null` if there are no further pages.
169+
*/
170+
nextCursor: string | null;
171+
/**
172+
* The URL of the next page of results, or `null` if there are no further pages.
173+
*/
174+
nextPage: string | null;
175+
}
176+
177+
interface TransactionalEmail {
178+
/** The ID of the transactional email. */
179+
id: string;
180+
/**
181+
* The name of the transactional email.
182+
*/
183+
name: string;
184+
/**
185+
* The date the email was last updated in ECMA-262 date-time format.
186+
* @see https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format
187+
*/
188+
lastUpdate: string;
189+
/**
190+
* Data variables in the transactional email.
191+
*/
192+
dataVariables: string[];
193+
}
194+
195+
interface ListTransactionalsResponse {
196+
pagination: PaginationData;
197+
data: TransactionalEmail[];
198+
}
199+
150200
class RateLimitExceededError extends Error {
151201
limit: number;
152202
remaining: number;
@@ -508,6 +558,34 @@ class LoopsClient {
508558
payload,
509559
});
510560
}
561+
562+
/**
563+
* List published transactional emails.
564+
*
565+
* @param {Object} params
566+
* @param {number} [params.perPage] How many results to return in each request. Must be between 10 and 50. Defaults to 20.
567+
* @param {string} [params.cursor] A cursor, to return a specific page of results. Cursors can be found from the `pagination.nextCursor` value in each response.
568+
*
569+
* @see https://loops.so/docs/api-reference/list-transactional-emails
570+
*
571+
* @returns {Object} List of transactional emails (JSON)
572+
*/
573+
async getTransactionalEmails({
574+
perPage,
575+
cursor,
576+
}: {
577+
perPage?: number;
578+
cursor?: string;
579+
} = {}): Promise<ListTransactionalsResponse> {
580+
let params: { perPage: string; cursor?: string } = {
581+
perPage: (perPage || 20).toString(),
582+
};
583+
if (cursor) params["cursor"] = cursor;
584+
return this._makeQuery({
585+
path: "v1/transactional",
586+
params,
587+
});
588+
}
511589
}
512590

513591
export { LoopsClient, RateLimitExceededError, APIError };

0 commit comments

Comments
 (0)