Skip to content

Commit 399ae0d

Browse files
committed
Added testApiKey method
1 parent 9e3eced commit 399ae0d

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ You can use custom contact properties in API calls. Please make sure to [add cus
5353

5454
## Methods
5555

56+
- [testApiKey()](#testapikey)
5657
- [createContact()](#createcontact)
5758
- [updateContact()](#updatecontact)
5859
- [findContact()](#findcontact)
@@ -64,6 +65,41 @@ You can use custom contact properties in API calls. Please make sure to [add cus
6465

6566
---
6667

68+
### testApiKey()
69+
70+
Test that an API key is valid.
71+
72+
[API Reference](https://loops.so/docs/api-reference/api-key)
73+
74+
#### Parameters
75+
76+
None
77+
78+
#### Example
79+
80+
```javascript
81+
const resp = await loops.testApiKey();
82+
```
83+
84+
#### Response
85+
86+
This method will return a success or error message:
87+
88+
```json
89+
{
90+
"success": true,
91+
"teamName": "My team"
92+
}
93+
```
94+
95+
```json
96+
{
97+
"error": "Invalid API key"
98+
}
99+
```
100+
101+
---
102+
67103
### createContact()
68104

69105
Create a new contact.
@@ -495,6 +531,7 @@ If your account has no custom fields, an empty list will be returned.
495531

496532
## Version history
497533

534+
- `v3.3.0` (Sep 9, 2024) - Added [`testApiKey()`](#testapikey) method.
498535
- `v3.2.0` (Aug 23, 2024) - Added support for a new `mailingLists` attribute in [`findContact()`](#findcontact).
499536
- `v3.1.1` (Aug 16, 2024) - Support for a new `isPublic` attribute in [`getMailingLists()`](#getmailinglists).
500537
- `v3.1.0` (Aug 12, 2024) - The SDK now accepts `null` as a value for contact properties in `createContact()`, `updateContact()` and `sendEvent()`, which allows you to reset/empty properties.

src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ interface QueryOptions {
55
params?: Record<string, string>;
66
}
77

8+
interface ApiKeySuccessResponse {
9+
success: true;
10+
teamName: string;
11+
}
12+
13+
interface ApiKeyErrorResponse {
14+
error: "Invalid API key";
15+
}
16+
17+
type ApiKeyResponse = ApiKeySuccessResponse | ApiKeyErrorResponse;
18+
819
interface ContactSuccessResponse {
920
success: true;
1021
id: string;
@@ -178,6 +189,19 @@ class LoopsClient {
178189
}
179190
}
180191

192+
/**
193+
* Test an API key.
194+
*
195+
* @see https://loops.so/docs/api-reference/api-key
196+
*
197+
* @returns {Object} Success or error message (JSON)
198+
*/
199+
async testApiKey(): Promise<ApiKeyResponse> {
200+
return this._makeQuery({
201+
path: "v1/api-key",
202+
});
203+
}
204+
181205
/**
182206
* Create a new contact.
183207
*

0 commit comments

Comments
 (0)