@bentonow/bento-node-sdk 0.2.1 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE → LICENSE.md} +1 -1
- package/README.md +604 -1031
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1306 -5
- package/dist/sdk/batch/enums.d.ts +8 -8
- package/dist/sdk/batch/errors.d.ts +18 -18
- package/dist/sdk/batch/events.d.ts +71 -71
- package/dist/sdk/batch/index.d.ts +55 -55
- package/dist/sdk/batch/types.d.ts +37 -37
- package/dist/sdk/broadcasts/index.d.ts +26 -0
- package/dist/sdk/broadcasts/types.d.ts +32 -0
- package/dist/sdk/client/errors.d.ts +12 -6
- package/dist/sdk/client/index.d.ts +94 -64
- package/dist/sdk/client/types.d.ts +3 -3
- package/dist/sdk/commands/enums.d.ts +12 -12
- package/dist/sdk/commands/index.d.ts +79 -79
- package/dist/sdk/commands/types.d.ts +32 -32
- package/dist/sdk/email-templates/index.d.ts +21 -0
- package/dist/sdk/email-templates/types.d.ts +23 -0
- package/dist/sdk/enums.d.ts +12 -9
- package/dist/sdk/errors.d.ts +2 -2
- package/dist/sdk/experimental/index.d.ts +75 -57
- package/dist/sdk/experimental/types.d.ts +71 -41
- package/dist/sdk/fields/index.d.ts +29 -29
- package/dist/sdk/fields/types.d.ts +17 -17
- package/dist/sdk/forms/index.d.ts +14 -14
- package/dist/sdk/forms/types.d.ts +28 -28
- package/dist/sdk/index.d.ts +11 -8
- package/dist/sdk/interfaces.d.ts +17 -13
- package/dist/sdk/sequences/index.d.ts +13 -0
- package/dist/sdk/sequences/types.d.ts +18 -0
- package/dist/sdk/stats/index.d.ts +24 -0
- package/dist/sdk/stats/types.d.ts +26 -0
- package/dist/sdk/subscribers/index.d.ts +20 -20
- package/dist/sdk/subscribers/types.d.ts +25 -25
- package/dist/sdk/tags/index.d.ts +20 -20
- package/dist/sdk/tags/types.d.ts +17 -17
- package/dist/sdk/types.d.ts +41 -41
- package/dist/sdk/workflows/index.d.ts +13 -0
- package/dist/sdk/workflows/types.d.ts +18 -0
- package/dist/versions/v1/index.d.ts +168 -132
- package/dist/versions/v1/types.d.ts +31 -31
- package/package.json +31 -44
- package/src/sdk/batch/events.ts +1 -1
- package/src/sdk/batch/index.ts +15 -22
- package/src/sdk/broadcasts/index.ts +44 -0
- package/src/sdk/broadcasts/types.ts +38 -0
- package/src/sdk/client/errors.ts +14 -0
- package/src/sdk/client/index.ts +205 -49
- package/src/sdk/commands/index.ts +54 -89
- package/src/sdk/email-templates/index.ts +39 -0
- package/src/sdk/email-templates/types.ts +27 -0
- package/src/sdk/enums.ts +3 -0
- package/src/sdk/experimental/index.ts +44 -26
- package/src/sdk/experimental/types.ts +35 -0
- package/src/sdk/fields/index.ts +1 -3
- package/src/sdk/forms/index.ts +4 -9
- package/src/sdk/forms/types.ts +1 -7
- package/src/sdk/index.ts +3 -0
- package/src/sdk/interfaces.ts +4 -0
- package/src/sdk/sequences/index.ts +21 -0
- package/src/sdk/sequences/types.ts +21 -0
- package/src/sdk/stats/index.ts +37 -0
- package/src/sdk/stats/types.ts +28 -0
- package/src/sdk/subscribers/index.ts +5 -15
- package/src/sdk/tags/index.ts +1 -3
- package/src/sdk/types.ts +1 -1
- package/src/sdk/workflows/index.ts +21 -0
- package/src/sdk/workflows/types.ts +21 -0
- package/src/versions/v1/index.ts +65 -10
- package/dist/bento-node-sdk.cjs.development.js +0 -2071
- package/dist/bento-node-sdk.cjs.development.js.map +0 -1
- package/dist/bento-node-sdk.cjs.production.min.js +0 -2
- package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
- package/dist/bento-node-sdk.esm.js +0 -2063
- package/dist/bento-node-sdk.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,1295 +1,868 @@
|
|
|
1
|
-
# Bento SDK
|
|
1
|
+
# Bento Node SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img align="right" src="https://app.bentonow.com/brand/logoanim.gif">
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> [!TIP]
|
|
6
|
+
> Need help? Join our [Discord](https://discord.gg/ssXXFRmt5F) or email jesse@bentonow.com for personalized support.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
The Bento Node.js SDK makes it quick and easy to build an excellent analytics experience in your Node.js application. We provide powerful and customizable APIs that can be used out-of-the-box to track your users' behavior and manage subscribers. We also expose low-level APIs so that you can build fully custom experiences.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
Get started with our [📚 integration guides](https://docs.bentonow.com), or [📘 browse the SDK reference](https://docs.bentonow.com/subscribers).
|
|
10
11
|
|
|
11
12
|
🐶 Battle-tested by [NativShark](https://nativshark.com) Bento Production (a Bento customer)!
|
|
12
13
|
|
|
13
14
|
❤️ Thank you @HelloKashif from [IPInfo](https://ipinfo.io) for your contribution.
|
|
15
|
+
|
|
14
16
|
❤️ Thank you @jonsherrard from [Devular](https://www.devular.com/) for your contribution.
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
- [Get Started](#Get-Started)
|
|
18
|
-
- [Modules](#Modules)
|
|
19
|
-
- [Analytics (Base Module)](#analytics-base-module)
|
|
20
|
-
- [tagSubscriber(parameters: TagSubscriberParameters): Promise\<boolean\>](#tagsubscriberparameters-tagsubscriberparameters-promiseboolean)
|
|
21
|
-
- [addSubscriber(parameters: AddSubscriberParameters): Promise\<boolean\>](#addsubscriberparameters-addsubscriberparameters-promiseboolean)
|
|
22
|
-
- [removeSubscriber(parameters: RemoveSubscriberParameters): Promise\<boolean\>](#removesubscriberparameters-removesubscriberparameters-promiseboolean)
|
|
23
|
-
- [updateFields(parameters: UpdateFieldsParameters\<S\>): Promise\<boolean\>](#updatefieldsparameters-updatefieldsparameterss-promiseboolean)
|
|
24
|
-
- [track(parameters: TrackParameters<S, E>): Promise<boolean>](#trackparameters-trackparameterss-e-promiseboolean)
|
|
25
|
-
- [trackPurchase(parameters: TrackPurchaseParameters): Promise\<boolean\>](#trackpurchaseparameters-trackpurchaseparameters-promiseboolean)
|
|
26
|
-
- [Batch](#Batch)
|
|
27
|
-
- [.importSubscribers(parameters: BatchImportSubscribersParameter\<S\>): Promise\<number\>](#batchimportsubscribersparameters-batchimportsubscribersparameters-promisenumber)
|
|
28
|
-
- [.importEvents(parameters: BatchImportEventsParameter\<S, E\>): Promise\<number\>](#batchimporteventsparameters-batchimporteventsparameters-e-promisenumber)
|
|
29
|
-
- [.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>](#batchsendtransactionalemailsparameters-batchsendtransactionalemailsparameters-e-promisenumber)
|
|
30
|
-
- [Commands](#Commands)
|
|
31
|
-
- [.addTag(parameters: AddTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsaddtagparameters-addtagparameters-promisesubscribers--null)
|
|
32
|
-
- [.removeTag(parameters: RemoveTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsremovetagparameters-removetagparameters-promisesubscribers--null)
|
|
33
|
-
- [.addField(parameters: AddFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsaddfieldparameters-addfieldparameterss-promisesubscribers--null)
|
|
34
|
-
- [.removeField(parameters: RemoveFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsremovefieldparameters-removefieldparameterss-promisesubscribers--null)
|
|
35
|
-
- [.subscribe(parameters: SubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null)
|
|
36
|
-
- [.unsubscribe(parameters: UnsubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null)
|
|
37
|
-
- [Experimental](#Experimental)
|
|
38
|
-
- [.validateEmail(parameters: ValidateEmailParameters): Promise\<boolean\>](#experimentalvalidateemailparameters-validateemailparameters-promiseboolean)
|
|
39
|
-
- [.guessGender(parameters: GuessGenderParameters): Promise\<GuessGenderResponse\>](#experimentalguessgenderparameters-guessgenderparameters-promiseguessgenderresponse)
|
|
40
|
-
- [.geolocate(parameters: GeolocateParameters): Promise\<LocationData | null\>](#experimentalgeolocateparameters-geolocateparameters-promiselocationdata--null)
|
|
41
|
-
- [.checkBlacklist(parameters: BlacklistParameters): Promise\<BlacklistResponse\>](#experimentalcheckblacklistparameters-blacklistparameters-promiseblacklistresponse)
|
|
42
|
-
- [Fields](#Fields)
|
|
43
|
-
- [.getFields(): Promise\<Field[] | null\>](#fieldsgetfields-promisefield--null)
|
|
44
|
-
- [.createField(parameters: CreateFieldParameters): Promise\<Field[] | null\>](#fieldscreatefieldparameters-createfieldparameters-promisefield--null)
|
|
45
|
-
- [Forms](#Forms)
|
|
46
|
-
- [.getResponses(formIdentifier: string): Promise\<FormResponse[] | null\>](#formsgetresponsesformidentifier-string-promiseformresponse--null)
|
|
47
|
-
- [Subscribers](#Subscribers)
|
|
48
|
-
- [.getSubscribers(parameters?: GetSubscribersParameters): Promise\<Subscriber\<S\> | null\>](#subscribersgetsubscribersparameters-getsubscribersparameters-promisesubscribers--null)
|
|
49
|
-
- [.createSubscriber(parameters: CreateSubscriberParameters): Promise\<Subscriber\<S\> | null\>](#subscriberscreatesubscriberparameters-createsubscriberparameters-promisesubscribers--null)
|
|
50
|
-
- [Tags](#Tags)
|
|
51
|
-
- [.getTags(): Promise\<Tag[] | null\>](#tagsgettags-promisetag--null)
|
|
52
|
-
- [.createTag(parameters: CreateTagParameters): Promise\<Tag[] | null\>](#tagscreatetagparameters-createtagparameters-promisetag--null)
|
|
53
|
-
- [Types Reference](#Types-Reference)
|
|
54
|
-
- [TypeScript](#TypeScript)
|
|
55
|
-
- [Generics](#Generics)
|
|
56
|
-
- [S](#s)
|
|
57
|
-
- [E](#e)
|
|
58
|
-
- [Things to Know](#Things-to-Know)
|
|
59
|
-
- [Contributing](#Contributing)
|
|
60
|
-
- [License](#License)
|
|
61
|
-
|
|
62
|
-
## Installation
|
|
63
|
-
|
|
64
|
-
Run the following command in your project folder.
|
|
18
|
+
[](https://github.com/bentonow/bento-node-sdk/actions/workflows/main.yml)
|
|
65
19
|
|
|
66
|
-
|
|
67
|
-
npm install @bentonow/bento-node-sdk --save
|
|
68
|
-
```
|
|
20
|
+
# Table of contents
|
|
69
21
|
|
|
70
|
-
|
|
22
|
+
- [Features](#features)
|
|
23
|
+
- [Requirements](#requirements)
|
|
24
|
+
- [Getting started](#getting-started)
|
|
25
|
+
- [Installation](#installation)
|
|
26
|
+
- [Integration](#integration)
|
|
27
|
+
- [Modules](#modules)
|
|
28
|
+
- [Type Reference](#types-reference)
|
|
29
|
+
- [Things to know](#things-to-know)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
- [License](#license)
|
|
71
32
|
|
|
72
|
-
|
|
33
|
+
## Features
|
|
73
34
|
|
|
74
|
-
|
|
35
|
+
- **Simple event tracking**: We make it easy for you to track user events and behavior in your application.
|
|
36
|
+
- **Subscriber management**: Easily add, update, and remove subscribers from your Bento account.
|
|
37
|
+
- **Custom fields**: Track and update custom fields for your subscribers to store additional data.
|
|
38
|
+
- **Purchase tracking**: Monitor customer purchases and calculate lifetime value (LTV) for your subscribers.
|
|
39
|
+
- **Batch operations**: Perform bulk imports of subscribers and events for efficient data management.
|
|
40
|
+
- **TypeScript support**: The SDK is written in TypeScript and provides type definitions for a better development experience.
|
|
75
41
|
|
|
76
|
-
|
|
77
|
-
import { Analytics } from '@bentonow/bento-node-sdk';
|
|
42
|
+
## Requirements
|
|
78
43
|
|
|
79
|
-
|
|
80
|
-
authentication: {
|
|
81
|
-
publishableKey: 'publishableKey',
|
|
82
|
-
secretKey: 'secretKey',
|
|
83
|
-
},
|
|
84
|
-
logErrors: false, // Set to true to see the HTTP errors logged
|
|
85
|
-
siteUuid: 'siteUuid',
|
|
86
|
-
});
|
|
44
|
+
The Bento Node.js SDK requires Node.js version 12 or later.
|
|
87
45
|
|
|
88
|
-
|
|
89
|
-
email: 'test@bentonow.com',
|
|
90
|
-
type: '$formSubmitted',
|
|
91
|
-
fields: {
|
|
92
|
-
first_name: 'Test',
|
|
93
|
-
last_name: 'Test',
|
|
94
|
-
},
|
|
95
|
-
details: {
|
|
96
|
-
fromCustomEvent: true,
|
|
97
|
-
},
|
|
98
|
-
}).then(result => console.log(result)).catch(error => console.error(error));
|
|
46
|
+
Bento Account for a valid **SITE_UUID**, **BENTO_PUBLISHABLE_KEY** & **BENTO_SECRET_KEY**.
|
|
99
47
|
|
|
100
|
-
|
|
101
|
-
email: 'test@bentonow.com',
|
|
102
|
-
purchaseDetails: {
|
|
103
|
-
unique: { key: 1234 }, // this key stops duplicate order values being tracked
|
|
104
|
-
value: { amount: 100, currency: 'USD' },
|
|
105
|
-
},
|
|
106
|
-
cart: {
|
|
107
|
-
abandoned_checkout_url: 'https://example.com',
|
|
108
|
-
},
|
|
109
|
-
});
|
|
48
|
+
## Getting started
|
|
110
49
|
|
|
111
|
-
|
|
50
|
+
### Installation
|
|
112
51
|
|
|
113
|
-
|
|
52
|
+
Install the Bento SDK in your project folder:
|
|
114
53
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
In addition to the top-level Analytics object, we also provide access to other parts of the API behind their corresponding modules. You can access these off of the main `Analytics` object.
|
|
54
|
+
```bash
|
|
118
55
|
|
|
119
|
-
|
|
56
|
+
# Using npm
|
|
57
|
+
npm install @bentonow/bento-node-sdk --save
|
|
120
58
|
|
|
121
|
-
|
|
59
|
+
# Using Bun
|
|
60
|
+
bun add @bentonow/bento-node-sdk
|
|
61
|
+
```
|
|
122
62
|
|
|
123
|
-
###
|
|
63
|
+
### Using Bun (Recommended)
|
|
124
64
|
|
|
125
|
-
|
|
65
|
+
```bash
|
|
66
|
+
# Install dependencies
|
|
67
|
+
bun install
|
|
126
68
|
|
|
127
|
-
|
|
69
|
+
# Run tests
|
|
70
|
+
bun test
|
|
128
71
|
|
|
129
|
-
|
|
72
|
+
# Run tests with coverage
|
|
73
|
+
bun test:coverage
|
|
130
74
|
|
|
131
|
-
|
|
75
|
+
# Build the package
|
|
76
|
+
bun run build
|
|
132
77
|
|
|
133
|
-
|
|
78
|
+
# Lint code
|
|
79
|
+
bun run lint
|
|
134
80
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
email: 'test@bentonow.com',
|
|
138
|
-
tagName: 'Test Tag',
|
|
139
|
-
})
|
|
140
|
-
.then(result => console.log(result))
|
|
141
|
-
.catch(error => console.error(error));
|
|
81
|
+
# Format code
|
|
82
|
+
bun run format
|
|
142
83
|
```
|
|
143
84
|
|
|
144
|
-
|
|
85
|
+
### Using npm
|
|
145
86
|
|
|
146
|
-
|
|
87
|
+
```bash
|
|
88
|
+
# Install dependencies
|
|
89
|
+
npm install
|
|
147
90
|
|
|
148
|
-
|
|
91
|
+
# Run tests
|
|
92
|
+
npm run test:npm
|
|
149
93
|
|
|
150
|
-
|
|
94
|
+
# Run tests with coverage
|
|
95
|
+
npm run test:coverage:npm
|
|
151
96
|
|
|
152
|
-
|
|
97
|
+
# Build the package
|
|
98
|
+
npm run build:npm
|
|
153
99
|
|
|
154
|
-
|
|
100
|
+
# Lint code
|
|
101
|
+
npm run lint
|
|
155
102
|
|
|
156
|
-
|
|
103
|
+
# Format code
|
|
104
|
+
npm run format
|
|
105
|
+
```
|
|
157
106
|
|
|
158
|
-
|
|
107
|
+
### Integration
|
|
159
108
|
|
|
160
|
-
|
|
161
|
-
bento.V1.addSubscriber({
|
|
162
|
-
email: 'test@bentonow.com',
|
|
163
|
-
})
|
|
164
|
-
.then(result => console.log(result))
|
|
165
|
-
.catch(error => console.error(error));
|
|
109
|
+
Initialize the Bento client and start tracking events:
|
|
166
110
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
111
|
+
```javascript
|
|
112
|
+
import { Analytics } from '@bentonow/bento-node-sdk';
|
|
113
|
+
|
|
114
|
+
const bento = new Analytics({
|
|
115
|
+
authentication: {
|
|
116
|
+
publishableKey: 'bento-publishable-key',
|
|
117
|
+
secretKey: 'bento-secret-key',
|
|
118
|
+
},
|
|
119
|
+
siteUuid: 'bento-site-uuid',
|
|
120
|
+
// Optional: Configure request timeout (default: 30000ms)
|
|
121
|
+
clientOptions: {
|
|
122
|
+
timeout: 30000,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
bento.V1.track({
|
|
127
|
+
email: 'user@example.com',
|
|
128
|
+
type: '$formSubmitted',
|
|
170
129
|
fields: {
|
|
171
|
-
|
|
172
|
-
|
|
130
|
+
first_name: 'John',
|
|
131
|
+
last_name: 'Doe',
|
|
132
|
+
},
|
|
133
|
+
details: {
|
|
134
|
+
fromCustomEvent: true,
|
|
173
135
|
},
|
|
174
|
-
})
|
|
175
|
-
.then(result => console.log(result))
|
|
176
|
-
.catch(error => console.error(error));
|
|
136
|
+
}).then((result) => console.log(result));
|
|
177
137
|
```
|
|
178
138
|
|
|
179
|
-
|
|
139
|
+
## Modules
|
|
180
140
|
|
|
181
|
-
|
|
141
|
+
The Bento SDK provides several modules for different operations:
|
|
182
142
|
|
|
183
|
-
|
|
143
|
+
### Analytics (Base Module)
|
|
184
144
|
|
|
185
|
-
|
|
145
|
+
Core functionality for tracking events and managing subscribers.
|
|
186
146
|
|
|
187
|
-
|
|
147
|
+
### Convenience Helpers
|
|
188
148
|
|
|
189
|
-
|
|
149
|
+
#### tagSubscriber
|
|
190
150
|
|
|
191
|
-
|
|
151
|
+
Tags a subscriber with a specific tag.
|
|
192
152
|
|
|
193
|
-
```
|
|
194
|
-
bento.V1.
|
|
195
|
-
email: '
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
.catch(error => console.error(error));
|
|
153
|
+
```javascript
|
|
154
|
+
bento.V1.tagSubscriber({
|
|
155
|
+
email: 'user@example.com',
|
|
156
|
+
tagName: 'New Customer',
|
|
157
|
+
}).then((result) => console.log(result));
|
|
199
158
|
```
|
|
200
159
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
### `updateFields(parameters: UpdateFieldsParameters<S>): Promise<boolean>`
|
|
204
|
-
|
|
205
|
-
**This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.addField`](#commandsaddfieldparameters-addfieldparameterss-promisesubscribers--null) method.
|
|
206
|
-
|
|
207
|
-
Sets the passed-in custom fields on the subscriber, creating the subscriber if it does not exist. If the fields are already set on the subscriber, the event will be sent, triggering any automations that take place upon fields being updated. Please be aware of the potential consequences.
|
|
160
|
+
#### addSubscriber
|
|
208
161
|
|
|
209
|
-
|
|
162
|
+
Adds a new subscriber to your Bento account.
|
|
210
163
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
```ts
|
|
216
|
-
bento.V1.updateFields({
|
|
217
|
-
email: 'test@bentonow.com',
|
|
164
|
+
```javascript
|
|
165
|
+
bento.V1.addSubscriber({
|
|
166
|
+
email: 'newuser@example.com',
|
|
218
167
|
fields: {
|
|
219
|
-
firstName: '
|
|
168
|
+
firstName: 'John',
|
|
169
|
+
lastName: 'Doe',
|
|
220
170
|
},
|
|
221
|
-
})
|
|
222
|
-
.then(result => console.log(result))
|
|
223
|
-
.catch(error => console.error(error));
|
|
171
|
+
}).then((result) => console.log(result));
|
|
224
172
|
```
|
|
225
173
|
|
|
226
|
-
|
|
174
|
+
#### removeSubscriber
|
|
227
175
|
|
|
228
|
-
|
|
176
|
+
Removes a subscriber from your Bento account.
|
|
229
177
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
178
|
+
```javascript
|
|
179
|
+
bento.V1.removeSubscriber({
|
|
180
|
+
email: 'user@example.com',
|
|
181
|
+
}).then((result) => console.log(result));
|
|
182
|
+
```
|
|
235
183
|
|
|
236
|
-
|
|
184
|
+
#### upsertSubscriber
|
|
237
185
|
|
|
238
|
-
|
|
186
|
+
Creates or updates a subscriber. The SDK queues the import job and then attempts to fetch
|
|
187
|
+
the subscriber record once the job has been accepted.
|
|
239
188
|
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
email: '
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
value: {
|
|
248
|
-
amount: 100,
|
|
249
|
-
currency: 'USD',
|
|
250
|
-
},
|
|
189
|
+
```javascript
|
|
190
|
+
const subscriber = await analytics.V1.upsertSubscriber({
|
|
191
|
+
email: 'user@example.com',
|
|
192
|
+
fields: {
|
|
193
|
+
firstName: 'John',
|
|
194
|
+
lastName: 'Doe',
|
|
195
|
+
company: 'Acme Inc',
|
|
251
196
|
},
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
197
|
+
tags: 'lead,mql',
|
|
198
|
+
remove_tags: 'customer',
|
|
199
|
+
});
|
|
255
200
|
```
|
|
256
201
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
### `track(parameters: TrackParameters<S, E>): Promise<boolean>`
|
|
202
|
+
> **Note:** Imports are processed asynchronously by Bento and may take 1-5 minutes to
|
|
203
|
+
> complete. If the subscriber is not yet available, the method will return `null`.
|
|
260
204
|
|
|
261
|
-
|
|
205
|
+
#### updateFields
|
|
262
206
|
|
|
263
|
-
|
|
207
|
+
Updates custom fields for a subscriber.
|
|
264
208
|
|
|
265
|
-
|
|
209
|
+
```javascript
|
|
210
|
+
bento.V1.updateFields({
|
|
211
|
+
email: 'user@example.com',
|
|
212
|
+
fields: {
|
|
213
|
+
lastPurchaseDate: new Date(),
|
|
214
|
+
},
|
|
215
|
+
}).then((result) => console.log(result));
|
|
216
|
+
```
|
|
266
217
|
|
|
267
|
-
|
|
218
|
+
#### track
|
|
268
219
|
|
|
269
|
-
|
|
220
|
+
Tracks a custom event for a subscriber.
|
|
270
221
|
|
|
271
|
-
```
|
|
222
|
+
```javascript
|
|
272
223
|
bento.V1.track({
|
|
273
|
-
email: '
|
|
274
|
-
type: '$
|
|
275
|
-
fields: {
|
|
276
|
-
firstName: 'Custom Name',
|
|
277
|
-
lastName: 'Custom Name',
|
|
278
|
-
},
|
|
224
|
+
email: 'user@example.com',
|
|
225
|
+
type: '$pageView',
|
|
279
226
|
details: {
|
|
280
|
-
|
|
227
|
+
url: '/products',
|
|
281
228
|
},
|
|
282
|
-
})
|
|
283
|
-
.then(result => console.log(result))
|
|
284
|
-
.catch(error => console.error(error));
|
|
229
|
+
}).then((result) => console.log(result));
|
|
285
230
|
```
|
|
286
231
|
|
|
287
|
-
|
|
232
|
+
#### trackPurchase
|
|
288
233
|
|
|
289
|
-
|
|
234
|
+
Tracks a purchase event for a subscriber.
|
|
290
235
|
|
|
291
|
-
|
|
236
|
+
```javascript
|
|
237
|
+
bento.V1.trackPurchase({
|
|
238
|
+
email: 'user@example.com',
|
|
239
|
+
purchaseDetails: {
|
|
240
|
+
unique: { key: 'order-123' },
|
|
241
|
+
value: { amount: 9999, currency: 'USD' },
|
|
242
|
+
},
|
|
243
|
+
}).then((result) => console.log(result));
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Low Level API calls
|
|
292
247
|
|
|
293
|
-
|
|
248
|
+
### Batch
|
|
294
249
|
|
|
295
|
-
|
|
250
|
+
Perform bulk operations for importing subscribers and events.
|
|
296
251
|
|
|
297
|
-
|
|
252
|
+
#### importSubscribers
|
|
298
253
|
|
|
299
|
-
|
|
254
|
+
Imports multiple subscribers in a single operation.
|
|
300
255
|
|
|
301
|
-
```
|
|
256
|
+
```javascript
|
|
302
257
|
bento.V1.Batch.importSubscribers({
|
|
303
258
|
subscribers: [
|
|
304
|
-
{
|
|
305
|
-
|
|
306
|
-
age: 21,
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
email: 'test2@bentonow.com',
|
|
310
|
-
some_custom_variable: 'tester-123',
|
|
311
|
-
primary_user: true,
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
email: 'test3@bentonow.com',
|
|
315
|
-
name: 'Test User',
|
|
316
|
-
},
|
|
259
|
+
{ email: 'user1@example.com', firstName: 'Alice' },
|
|
260
|
+
{ email: 'user2@example.com', firstName: 'Bob' },
|
|
317
261
|
],
|
|
318
|
-
})
|
|
319
|
-
.then(result => console.log(result))
|
|
320
|
-
.catch(error => console.error(error));
|
|
262
|
+
}).then((result) => console.log(result));
|
|
321
263
|
```
|
|
322
264
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
### `Batch.importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number>`
|
|
326
|
-
|
|
327
|
-
Creates a batch job to import events into the system. You can pass in between 1 and 100 events to import. Each event must have an email and a type. In addition to this, you my pass in additional data in the `details` property,
|
|
265
|
+
#### importEvents
|
|
328
266
|
|
|
329
|
-
|
|
267
|
+
Imports multiple events in a single operation.
|
|
330
268
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
```ts
|
|
269
|
+
```javascript
|
|
334
270
|
bento.V1.Batch.importEvents({
|
|
335
271
|
events: [
|
|
336
|
-
{
|
|
337
|
-
|
|
338
|
-
type: BentoEvents.SUBSCRIBE,
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
email: 'test@bentonow.com',
|
|
342
|
-
type: BentoEvents.UNSUBSCRIBE,
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
email: 'test@bentonow.com',
|
|
346
|
-
type: BentoEvents.REMOVE_TAG,
|
|
347
|
-
details: {
|
|
348
|
-
tag: 'tag_to_remove',
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
email: 'test@bentonow.com',
|
|
353
|
-
type: BentoEvents.TAG,
|
|
354
|
-
details: {
|
|
355
|
-
tag: 'tag_to_add',
|
|
356
|
-
},
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
email: 'test@bentonow.com',
|
|
360
|
-
details: {
|
|
361
|
-
customData: 'Used internally.',
|
|
362
|
-
},
|
|
363
|
-
type: '$custom.myEvent,
|
|
364
|
-
},
|
|
272
|
+
{ email: 'user@example.com', type: '$login' },
|
|
273
|
+
{ email: 'user@example.com', type: '$pageView', details: { url: '/home' } },
|
|
365
274
|
],
|
|
366
|
-
})
|
|
367
|
-
.then(result => console.log(result))
|
|
368
|
-
.catch(error => console.error(error));
|
|
275
|
+
}).then((result) => console.log(result));
|
|
369
276
|
```
|
|
370
277
|
|
|
371
|
-
|
|
278
|
+
### Broadcast Management
|
|
372
279
|
|
|
373
|
-
|
|
280
|
+
#### getBroadcasts
|
|
374
281
|
|
|
375
|
-
|
|
282
|
+
Retrieves all broadcasts:
|
|
376
283
|
|
|
377
|
-
|
|
284
|
+
```javascript
|
|
285
|
+
const broadcasts = await analytics.V1.Broadcasts.getBroadcasts();
|
|
286
|
+
```
|
|
378
287
|
|
|
379
|
-
|
|
288
|
+
#### createBroadcast
|
|
380
289
|
|
|
381
|
-
|
|
290
|
+
Creates new broadcast campaigns:
|
|
382
291
|
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
link: 'https://example.com/test',
|
|
394
|
-
}, // optional — provide your own Liquid tags to be injected into the email.
|
|
292
|
+
```javascript
|
|
293
|
+
const broadcasts = await analytics.V1.Broadcasts.createBroadcast([
|
|
294
|
+
{
|
|
295
|
+
name: 'Weekly Newsletter',
|
|
296
|
+
subject: 'Your Weekly Update',
|
|
297
|
+
content: '<p>Hi {{ name }},</p>...',
|
|
298
|
+
type: 'html',
|
|
299
|
+
from: {
|
|
300
|
+
name: 'John Doe',
|
|
301
|
+
email: 'john@example.com',
|
|
395
302
|
},
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
303
|
+
inclusive_tags: 'lead,mql',
|
|
304
|
+
exclusive_tags: 'unsubscribed',
|
|
305
|
+
segment_id: 'segment_123',
|
|
306
|
+
batch_size_per_hour: 1000,
|
|
307
|
+
},
|
|
308
|
+
]);
|
|
400
309
|
```
|
|
401
310
|
|
|
402
|
-
|
|
311
|
+
### Transactional Emails
|
|
403
312
|
|
|
404
|
-
|
|
313
|
+
#### createEmails
|
|
405
314
|
|
|
406
|
-
|
|
315
|
+
Creates a new transactional email:
|
|
407
316
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
317
|
+
```javascript
|
|
318
|
+
const result = await bento.V1.Batch.sendTransactionalEmails({
|
|
319
|
+
emails: [
|
|
320
|
+
{
|
|
321
|
+
to: 'recipient@example.com', // just the email, recipient name is ignored.
|
|
322
|
+
from: 'sender@example.com', // MUST be an existing Author in your account (Emails -> Authors)
|
|
323
|
+
subject: 'Welcome {{ name }}',
|
|
324
|
+
html_body: '<p>Hello {{ name }}, welcome to our service!</p>',
|
|
325
|
+
transactional: false, // Set to true to send as a transactional email IF you want to ignore if the user has unsubscribed. USE WITH CAUTION!
|
|
326
|
+
personalizations: {
|
|
327
|
+
name: 'John Doe',
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
});
|
|
421
332
|
```
|
|
422
333
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
### `Commands.removeTag(parameters: RemoveTagParameters): Promise<Subscriber<S> | null>`
|
|
426
|
-
|
|
427
|
-
Removes the specified tag from the subscriber with the matching email.
|
|
334
|
+
### Email Structure
|
|
428
335
|
|
|
429
|
-
|
|
336
|
+
Each email object requires:
|
|
430
337
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
.catch(error => console.error(error));
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
---
|
|
338
|
+
- **to:** Recipient email address
|
|
339
|
+
- **from:** Sender email address
|
|
340
|
+
- **subject:** Email subject (supports liquid templates)
|
|
341
|
+
- **html_body:** HTML email content (supports liquid templates)
|
|
342
|
+
- **transactional:** true/false: defaults to false, must be true to send to unsubscribed users
|
|
343
|
+
- **personalizations:** Optional object for liquid template variables
|
|
441
344
|
|
|
442
|
-
|
|
345
|
+
#### Constraints
|
|
443
346
|
|
|
444
|
-
**
|
|
347
|
+
- **Batch size:** 1-100 emails per request
|
|
348
|
+
- **Errors:** Throws TooFewEmailsError or TooManyEmailsError for invalid counts
|
|
349
|
+
- **Returns:** Number of emails successfully queued
|
|
445
350
|
|
|
446
|
-
|
|
351
|
+
### Statistics
|
|
447
352
|
|
|
448
|
-
|
|
353
|
+
#### getSiteStats
|
|
449
354
|
|
|
450
|
-
|
|
355
|
+
Retrieves overall site statistics:
|
|
451
356
|
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
357
|
+
```javascript
|
|
358
|
+
const stats = await analytics.V1.Stats.getSiteStats();
|
|
359
|
+
// Returns:
|
|
360
|
+
// {
|
|
361
|
+
// total_subscribers: 1000,
|
|
362
|
+
// active_subscribers: 950,
|
|
363
|
+
// unsubscribed_count: 50,
|
|
364
|
+
// broadcast_count: 25,
|
|
365
|
+
// average_open_rate: 45.5,
|
|
366
|
+
// average_click_rate: 12.3
|
|
367
|
+
// }
|
|
462
368
|
```
|
|
463
369
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
### `Commands.removeField(parameters: RemoveFieldParameters<S>): Promise<Subscriber<S> | null>`
|
|
370
|
+
#### getSegmentStats
|
|
467
371
|
|
|
468
|
-
|
|
372
|
+
Retrieves statistics for a specific segment:
|
|
469
373
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
374
|
+
```javascript
|
|
375
|
+
const segmentStats = await analytics.V1.Stats.getSegmentStats('segment_123');
|
|
376
|
+
// Returns:
|
|
377
|
+
// {
|
|
378
|
+
// segment_id: 'segment_123',
|
|
379
|
+
// subscriber_count: 500,
|
|
380
|
+
// growth_rate: 2.5,
|
|
381
|
+
// engagement_rate: 35.8,
|
|
382
|
+
// last_updated: '2024-01-01T00:00:00Z'
|
|
383
|
+
// }
|
|
479
384
|
```
|
|
480
385
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
386
|
+
#### getReportStats
|
|
387
|
+
|
|
388
|
+
Retrieves statistics for a specific report:
|
|
389
|
+
|
|
390
|
+
```javascript
|
|
391
|
+
const reportStats = await analytics.V1.Stats.getReportStats('report_123');
|
|
392
|
+
// Returns:
|
|
393
|
+
// {
|
|
394
|
+
// report_id: 'report_123',
|
|
395
|
+
// total_sent: 1000,
|
|
396
|
+
// total_opens: 750,
|
|
397
|
+
// unique_opens: 500,
|
|
398
|
+
// total_clicks: 250,
|
|
399
|
+
// unique_clicks: 200,
|
|
400
|
+
// unsubscribes: 5,
|
|
401
|
+
// spam_reports: 1
|
|
402
|
+
// }
|
|
403
|
+
```
|
|
484
404
|
|
|
485
|
-
|
|
405
|
+
### Commands
|
|
486
406
|
|
|
487
|
-
|
|
407
|
+
Execute specific commands for subscriber management.
|
|
488
408
|
|
|
489
|
-
|
|
409
|
+
#### addTag
|
|
490
410
|
|
|
491
|
-
|
|
411
|
+
Adds a tag to a subscriber.
|
|
492
412
|
|
|
493
|
-
```
|
|
494
|
-
bento.V1.Commands.
|
|
495
|
-
email: '
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
.catch(error => console.error(error));
|
|
413
|
+
```javascript
|
|
414
|
+
bento.V1.Commands.addTag({
|
|
415
|
+
email: 'user@example.com',
|
|
416
|
+
tagName: 'VIP',
|
|
417
|
+
}).then((result) => console.log(result));
|
|
499
418
|
```
|
|
500
419
|
|
|
501
|
-
|
|
420
|
+
#### removeTag
|
|
502
421
|
|
|
503
|
-
|
|
422
|
+
Removes a tag from a subscriber.
|
|
504
423
|
|
|
505
|
-
|
|
424
|
+
```javascript
|
|
425
|
+
bento.V1.Commands.removeTag({
|
|
426
|
+
email: 'user@example.com',
|
|
427
|
+
tagName: 'VIP',
|
|
428
|
+
}).then((result) => console.log(result));
|
|
429
|
+
```
|
|
506
430
|
|
|
507
|
-
|
|
431
|
+
#### addField
|
|
508
432
|
|
|
509
|
-
|
|
433
|
+
Adds a custom field to a subscriber.
|
|
510
434
|
|
|
511
|
-
```
|
|
512
|
-
bento.V1.Commands.
|
|
513
|
-
email: '
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
435
|
+
```javascript
|
|
436
|
+
bento.V1.Commands.addField({
|
|
437
|
+
email: 'user@example.com',
|
|
438
|
+
field: {
|
|
439
|
+
key: 'favoriteColor',
|
|
440
|
+
value: 'blue',
|
|
441
|
+
},
|
|
442
|
+
}).then((result) => console.log(result));
|
|
517
443
|
```
|
|
518
444
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
### `Commands.changeEmail(parameters: ChangeEmailParameters): Promise<Subscriber<S> | null>`
|
|
445
|
+
#### removeField
|
|
522
446
|
|
|
523
|
-
|
|
447
|
+
Removes a custom field from a subscriber.
|
|
524
448
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
newEmail: 'new@bentonow.com',
|
|
531
|
-
})
|
|
532
|
-
.then(result => console.log(result))
|
|
533
|
-
.catch(error => console.error(error));
|
|
449
|
+
```javascript
|
|
450
|
+
bento.V1.Commands.removeField({
|
|
451
|
+
email: 'user@example.com',
|
|
452
|
+
fieldName: 'favoriteColor',
|
|
453
|
+
}).then((result) => console.log(result));
|
|
534
454
|
```
|
|
535
455
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
### `Experimental.validateEmail(parameters: ValidateEmailParameters): Promise<boolean>`
|
|
456
|
+
### Experimental
|
|
539
457
|
|
|
540
|
-
|
|
458
|
+
Access experimental features (use with caution).
|
|
541
459
|
|
|
542
|
-
|
|
460
|
+
#### validateEmail
|
|
543
461
|
|
|
544
|
-
|
|
462
|
+
Attempts to validate an email address.
|
|
545
463
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
```ts
|
|
464
|
+
```javascript
|
|
549
465
|
bento.V1.Experimental.validateEmail({
|
|
550
|
-
email: '
|
|
551
|
-
})
|
|
552
|
-
.then(result => console.log(result))
|
|
553
|
-
.catch(error => console.error(error));
|
|
466
|
+
email: 'user@example.com',
|
|
467
|
+
}).then((result) => console.log(result));
|
|
554
468
|
```
|
|
555
469
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
### `Experimental.guessGender(parameters: GuessGenderParameters): Promise<GuessGenderResponse>`
|
|
470
|
+
#### guessGender
|
|
559
471
|
|
|
560
|
-
|
|
472
|
+
Attempts to guess the gender based on a given name.
|
|
561
473
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
It is possible for the gender to be unknown if the system cannot confidently conclude what gender it may be.
|
|
565
|
-
|
|
566
|
-
Reference Types: [GuessGenderParameters](#GuessGenderParameters), [GuessGenderResponse](#GuessGenderResponse)
|
|
567
|
-
|
|
568
|
-
```ts
|
|
474
|
+
```javascript
|
|
569
475
|
bento.V1.Experimental.guessGender({
|
|
570
|
-
name: '
|
|
571
|
-
})
|
|
572
|
-
.then(result => console.log(result))
|
|
573
|
-
.catch(error => console.error(error));
|
|
476
|
+
name: 'Alex',
|
|
477
|
+
}).then((result) => console.log(result));
|
|
574
478
|
```
|
|
575
479
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
### `Experimental.geolocate(parameters: GeolocateParameters): Promise<LocationData | null>`
|
|
480
|
+
is blacklisted:
|
|
579
481
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
```ts
|
|
587
|
-
bento.V1.Experimental.geolocate({
|
|
588
|
-
ip: '127.0.0.1',
|
|
589
|
-
})
|
|
590
|
-
.then(result => console.log(result))
|
|
591
|
-
.catch(error => console.error(error));
|
|
482
|
+
```javascript
|
|
483
|
+
const blacklistStatus = await analytics.V1.Experimental.getBlacklistStatus({
|
|
484
|
+
domain: 'example.com',
|
|
485
|
+
// or ipAddress: '192.168.1.1'
|
|
486
|
+
});
|
|
592
487
|
```
|
|
593
488
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
489
|
+
#### getContentModeration
|
|
490
|
+
|
|
491
|
+
Performs content moderation on text:
|
|
492
|
+
|
|
493
|
+
```javascript
|
|
494
|
+
const moderationResult =
|
|
495
|
+
await analytics.V1.Experimental.getContentModeration('Content to moderate');
|
|
496
|
+
// Returns:
|
|
497
|
+
// {
|
|
498
|
+
// flagged: boolean,
|
|
499
|
+
// categories: {
|
|
500
|
+
// hate: boolean,
|
|
501
|
+
// 'hate/threatening': boolean,
|
|
502
|
+
// 'self-harm': boolean,
|
|
503
|
+
// ...
|
|
504
|
+
// },
|
|
505
|
+
// category_scores: {
|
|
506
|
+
// hate: number,
|
|
507
|
+
// 'hate/threatening': number,
|
|
508
|
+
// ...
|
|
509
|
+
// }
|
|
510
|
+
// }
|
|
511
|
+
```
|
|
599
512
|
|
|
600
|
-
|
|
513
|
+
#### geoLocateIP
|
|
601
514
|
|
|
602
|
-
|
|
515
|
+
Gets detailed geolocation information for an IP address:
|
|
603
516
|
|
|
604
|
-
```
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
517
|
+
```javascript
|
|
518
|
+
const location = await analytics.V1.Experimental.geoLocateIP('192.168.1.1');
|
|
519
|
+
// Returns:
|
|
520
|
+
// {
|
|
521
|
+
// city_name: 'San Francisco',
|
|
522
|
+
// country_name: 'United States',
|
|
523
|
+
// latitude: 37.7749,
|
|
524
|
+
// longitude: -122.4194,
|
|
525
|
+
// ...
|
|
526
|
+
// }
|
|
610
527
|
```
|
|
611
528
|
|
|
612
|
-
|
|
529
|
+
### Fields
|
|
613
530
|
|
|
614
|
-
|
|
531
|
+
Manage custom fields for your subscribers.
|
|
615
532
|
|
|
616
|
-
|
|
533
|
+
#### getFields
|
|
617
534
|
|
|
618
|
-
|
|
535
|
+
Retrieves all custom fields defined in your Bento account.
|
|
619
536
|
|
|
620
|
-
```
|
|
621
|
-
bento.V1.
|
|
622
|
-
email: 'test@bentonow.com',
|
|
623
|
-
})
|
|
624
|
-
.then(result => console.log(result))
|
|
625
|
-
.catch(error => console.error(error));
|
|
537
|
+
```javascript
|
|
538
|
+
bento.V1.Fields.getFields().then((fields) => console.log(fields));
|
|
626
539
|
```
|
|
627
540
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
### `Fields.createField(parameters: CreateFieldParameters): Promise<Field[] | null>`
|
|
631
|
-
|
|
632
|
-
Creates a field inside of Bento. The name of the field is automatically generated from the key that is passed in upon creation. For example:
|
|
541
|
+
#### createField
|
|
633
542
|
|
|
634
|
-
|
|
635
|
-
| ----------------- | ----------------- |
|
|
636
|
-
| `'thisIsAKey'` | `'This Is A Key'` |
|
|
637
|
-
| `'this is a key'` | `'This Is A Key'` |
|
|
638
|
-
| `'this-is-a-key'` | `'This Is A Key'` |
|
|
639
|
-
| `'this_is_a_key'` | `'This Is A Key'` |
|
|
543
|
+
Creates a new custom field in your Bento account.
|
|
640
544
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
```ts
|
|
545
|
+
```javascript
|
|
644
546
|
bento.V1.Fields.createField({
|
|
645
|
-
key: '
|
|
646
|
-
})
|
|
647
|
-
.then(result => console.log(result))
|
|
648
|
-
.catch(error => console.error(error));
|
|
547
|
+
key: 'loyaltyPoints',
|
|
548
|
+
}).then((result) => console.log(result));
|
|
649
549
|
```
|
|
650
550
|
|
|
651
|
-
|
|
551
|
+
### Forms
|
|
652
552
|
|
|
653
|
-
|
|
553
|
+
Retrieve form responses.
|
|
654
554
|
|
|
655
|
-
|
|
555
|
+
#### getResponses
|
|
656
556
|
|
|
657
|
-
|
|
557
|
+
Retrieves responses for a specific form.
|
|
658
558
|
|
|
659
|
-
```
|
|
660
|
-
bento.V1.Forms.getResponses('
|
|
661
|
-
.then(result => console.log(result))
|
|
662
|
-
.catch(error => console.error(error));
|
|
559
|
+
```javascript
|
|
560
|
+
bento.V1.Forms.getResponses('form-id-123').then((responses) => console.log(responses));
|
|
663
561
|
```
|
|
664
562
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
### `Subscribers.getSubscribers(parameters?: GetSubscribersParameters): Promise<Subscriber<S> | null>`
|
|
563
|
+
### Subscribers
|
|
668
564
|
|
|
669
|
-
|
|
565
|
+
Manage individual subscribers.
|
|
670
566
|
|
|
671
|
-
|
|
567
|
+
#### getSubscribers
|
|
672
568
|
|
|
673
|
-
|
|
674
|
-
bento.V1.Subscribers.getSubscribers({
|
|
675
|
-
uuid: '1234',
|
|
676
|
-
})
|
|
677
|
-
.then(result => console.log(result))
|
|
678
|
-
.catch(error => console.error(error));
|
|
569
|
+
Retrieves subscriber information.
|
|
679
570
|
|
|
571
|
+
```javascript
|
|
680
572
|
bento.V1.Subscribers.getSubscribers({
|
|
681
|
-
email: '
|
|
682
|
-
})
|
|
683
|
-
.then(result => console.log(result))
|
|
684
|
-
.catch(error => console.error(error));
|
|
573
|
+
email: 'user@example.com',
|
|
574
|
+
}).then((subscriber) => console.log(subscriber));
|
|
685
575
|
```
|
|
686
576
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
### `Subscribers.createSubscriber(parameters: CreateSubscriberParameters): Promise<Subscriber<S> | null>`
|
|
690
|
-
|
|
691
|
-
Creates a subscriber inside of Bento.
|
|
577
|
+
#### createSubscriber
|
|
692
578
|
|
|
693
|
-
|
|
579
|
+
Creates a new subscriber in your Bento account.
|
|
694
580
|
|
|
695
|
-
```
|
|
581
|
+
```javascript
|
|
696
582
|
bento.V1.Subscribers.createSubscriber({
|
|
697
|
-
email: '
|
|
698
|
-
})
|
|
699
|
-
.then(result => console.log(result))
|
|
700
|
-
.catch(error => console.error(error));
|
|
583
|
+
email: 'newuser@example.com',
|
|
584
|
+
}).then((result) => console.log(result));
|
|
701
585
|
```
|
|
702
586
|
|
|
703
|
-
|
|
587
|
+
### Tags
|
|
704
588
|
|
|
705
|
-
|
|
589
|
+
Create and manage tags for subscriber segmentation.
|
|
706
590
|
|
|
707
|
-
|
|
591
|
+
#### getTags
|
|
708
592
|
|
|
709
|
-
|
|
593
|
+
Retrieves all tags defined in your Bento account.
|
|
710
594
|
|
|
711
|
-
```
|
|
712
|
-
bento.V1.Tags.getTags()
|
|
713
|
-
.then(result => console.log(result))
|
|
714
|
-
.catch(error => console.error(error));
|
|
595
|
+
```javascript
|
|
596
|
+
bento.V1.Tags.getTags().then((tags) => console.log(tags));
|
|
715
597
|
```
|
|
716
598
|
|
|
717
|
-
|
|
599
|
+
#### createTag
|
|
718
600
|
|
|
719
|
-
|
|
601
|
+
Creates a new tag in your Bento account.
|
|
720
602
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
Reference Types: [Tag](#Tag)
|
|
724
|
-
|
|
725
|
-
```ts
|
|
603
|
+
```javascript
|
|
726
604
|
bento.V1.Tags.createTag({
|
|
727
|
-
name: '
|
|
728
|
-
})
|
|
729
|
-
.then(result => console.log(result))
|
|
730
|
-
.catch(error => console.error(error));
|
|
605
|
+
name: 'Premium Customer',
|
|
606
|
+
}).then((result) => console.log(result));
|
|
731
607
|
```
|
|
732
608
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
| Property | Type | Default | Required |
|
|
761
|
-
| -------- | -------- | ------- | -------- |
|
|
762
|
-
| email | `string` | _none_ | ✔️ |
|
|
763
|
-
| tagName | `string` | _none_ | ✔️ |
|
|
764
|
-
|
|
765
|
-
---
|
|
766
|
-
|
|
767
|
-
### `BatchImportEventsParameter<S, E>`
|
|
768
|
-
|
|
769
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
770
|
-
|
|
771
|
-
The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
772
|
-
|
|
773
|
-
| Property | Type | Default | Required |
|
|
774
|
-
| -------- | ----------------------------------------- | ------- | -------- |
|
|
775
|
-
| events | [`BentoEvent<S, E>[]`](#BentoEvent<S, E>) | _none_ | ✔️ |
|
|
776
|
-
|
|
777
|
-
---
|
|
778
|
-
|
|
779
|
-
### `BatchImportSubscribersParameter<S>`
|
|
780
|
-
|
|
781
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
782
|
-
|
|
783
|
-
| Property | Type | Default | Required |
|
|
784
|
-
| ----------- | ------------------------------------ | ------- | -------- |
|
|
785
|
-
| subscribers | `({ email: string } & Partial<S>)[]` | _none_ | ✔️ |
|
|
786
|
-
|
|
787
|
-
---
|
|
788
|
-
|
|
789
|
-
### `BentoEvent<S, E>`
|
|
790
|
-
|
|
791
|
-
This type is a discriminated union of a few different types. Each of these types are documented below:
|
|
792
|
-
|
|
793
|
-
#### `BaseEvent<E>`
|
|
794
|
-
|
|
795
|
-
The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
796
|
-
|
|
797
|
-
| Property | Type | Default | Required |
|
|
798
|
-
| -------- | ------------------------ | ------- | -------- |
|
|
799
|
-
| date | `Date` | _none_ | ❌ |
|
|
800
|
-
| details | `{ [key: string]: any }` | _none_ | ✔️ |
|
|
801
|
-
| email | `string` | _none_ | ✔️ |
|
|
802
|
-
| type | `string` | _none_ | ✔️ |
|
|
803
|
-
|
|
804
|
-
#### `PurchaseEvent`
|
|
805
|
-
|
|
806
|
-
| Property | Type | Default | Required |
|
|
807
|
-
| -------- | --------------------------------------- | ------- | -------- |
|
|
808
|
-
| date | `Date` | _none_ | ❌ |
|
|
809
|
-
| details | [`PurchaseDetails`](#PurchaseDetails) | _none_ | ✔️ |
|
|
810
|
-
| email | `string` | _none_ | ✔️ |
|
|
811
|
-
| type | `BentoEvents.PURCHASE` \| `'$purchase'` | _none_ | ✔️ |
|
|
812
|
-
|
|
813
|
-
#### `SubscribeEvent<S>`
|
|
814
|
-
|
|
815
|
-
| Property | Type | Default | Required |
|
|
816
|
-
| -------- | ----------------------------------------- | ------- | -------- |
|
|
817
|
-
| date | `Date` | _none_ | ❌ |
|
|
818
|
-
| email | `string` | _none_ | ✔️ |
|
|
819
|
-
| fields | `Partial<S>` | _none_ | ❌ |
|
|
820
|
-
| type | `BentoEvents.SUBSCRIBE` \| `'$subscribe'` | _none_ | ✔️ |
|
|
821
|
-
|
|
822
|
-
#### `TagEvent`
|
|
823
|
-
|
|
824
|
-
| Property | Type | Default | Required |
|
|
825
|
-
| -------- | ----------------------------- | ------- | -------- |
|
|
826
|
-
| date | `Date` | _none_ | ❌ |
|
|
827
|
-
| details | `{ tag: string }` | _none_ | ✔️ |
|
|
828
|
-
| email | `string` | _none_ | ✔️ |
|
|
829
|
-
| type | `BentoEvents.TAG` \| `'$tag'` | _none_ | ✔️ |
|
|
830
|
-
|
|
831
|
-
#### `UnsubscribeEvent`
|
|
832
|
-
|
|
833
|
-
| Property | Type | Default | Required |
|
|
834
|
-
| -------- | --------------------------------------------- | ------- | -------- |
|
|
835
|
-
| date | `Date` | _none_ | ❌ |
|
|
836
|
-
| email | `string` | _none_ | ✔️ |
|
|
837
|
-
| type | `BentoEvents.UNSUBSCRIBE` \| `'$unsubscribe'` | _none_ | ✔️ |
|
|
838
|
-
|
|
839
|
-
#### `UpdateFieldsEvent<S>`
|
|
840
|
-
|
|
841
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
842
|
-
|
|
843
|
-
| Property | Type | Default | Required |
|
|
844
|
-
| -------- | ------------------------------------------------- | ------- | -------- |
|
|
845
|
-
| date | `Date` | _none_ | ❌ |
|
|
846
|
-
| email | `string` | _none_ | ✔️ |
|
|
847
|
-
| type | `BentoEvents.UPDATE_FIELDS` \| `'$update_fields'` | _none_ | ✔️ |
|
|
848
|
-
| fields | `Partial<S>` | _none_ | ✔️ |
|
|
849
|
-
|
|
850
|
-
---
|
|
851
|
-
|
|
852
|
-
### `BlacklistParameters`
|
|
853
|
-
|
|
854
|
-
Note that this takes either `domain` _or_ `ip`, but never both.
|
|
855
|
-
|
|
856
|
-
| Property | Type | Default | Required |
|
|
857
|
-
| -------- | -------- | ------- | -------- |
|
|
858
|
-
| domain | `string` | _none_ | ✔️ |
|
|
859
|
-
|
|
860
|
-
| Property | Type | Default | Required |
|
|
861
|
-
| -------- | -------- | ------- | -------- |
|
|
862
|
-
| ip | `string` | _none_ | ✔️ |
|
|
863
|
-
|
|
864
|
-
---
|
|
865
|
-
|
|
866
|
-
### `BlacklistResponse`
|
|
867
|
-
|
|
868
|
-
The results is an object where the key is the name of the blacklist that was checked, and the value is whether or not the domain/IP appeared on that blacklist.
|
|
869
|
-
|
|
870
|
-
| Property | Type | Default | Required |
|
|
871
|
-
| ----------- | ---------------------------- | ------- | -------- |
|
|
872
|
-
| description | `string` | _none_ | ✔️ |
|
|
873
|
-
| query | `string` | _none_ | ✔️ |
|
|
874
|
-
| results | `{ [key: string]: boolean }` | _none_ | ✔️ |
|
|
875
|
-
|
|
876
|
-
---
|
|
877
|
-
|
|
878
|
-
### `BrowserData`
|
|
879
|
-
|
|
880
|
-
| Property | Type | Default | Required |
|
|
881
|
-
| ---------- | -------- | ------- | -------- |
|
|
882
|
-
| height | `string` | _none_ | ✔️ |
|
|
883
|
-
| user_agent | `string` | _none_ | ✔️ |
|
|
884
|
-
| width | `string` | _none_ | ✔️ |
|
|
885
|
-
|
|
886
|
-
---
|
|
887
|
-
|
|
888
|
-
### `ChangeEmailParameters`
|
|
889
|
-
|
|
890
|
-
| Property | Type | Default | Required |
|
|
891
|
-
| -------- | -------- | ------- | -------- |
|
|
892
|
-
| oldEmail | `string` | _none_ | ✔️ |
|
|
893
|
-
| newEmail | `string` | _none_ | ✔️ |
|
|
894
|
-
|
|
895
|
-
---
|
|
896
|
-
|
|
897
|
-
### `CreateFieldParameters`
|
|
898
|
-
|
|
899
|
-
| Property | Type | Default | Required |
|
|
900
|
-
| -------- | -------- | ------- | -------- |
|
|
901
|
-
| key | `string` | _none_ | ✔️ |
|
|
902
|
-
|
|
903
|
-
---
|
|
904
|
-
|
|
905
|
-
### `CreateSubscriberParameters`
|
|
906
|
-
|
|
907
|
-
| Property | Type | Default | Required |
|
|
908
|
-
| -------- | -------- | ------- | -------- |
|
|
909
|
-
| email | `string` | _none_ | ✔️ |
|
|
910
|
-
|
|
911
|
-
### `CreateTagParameters`
|
|
912
|
-
|
|
913
|
-
| Property | Type | Default | Required |
|
|
914
|
-
| -------- | -------- | ------- | -------- |
|
|
915
|
-
| name | `string` | _none_ | ✔️ |
|
|
916
|
-
|
|
917
|
-
---
|
|
918
|
-
|
|
919
|
-
### `EntityType`
|
|
920
|
-
|
|
921
|
-
This is an enum with the following values:
|
|
922
|
-
|
|
923
|
-
| Name | Value |
|
|
924
|
-
| --------------- | ------------------- |
|
|
925
|
-
| EVENTS | `'events'` |
|
|
926
|
-
| TAGS | `'tags'` |
|
|
927
|
-
| VISITORS | `'visitors'` |
|
|
928
|
-
| VISITORS_FIELDS | `'visitors-fields'` |
|
|
929
|
-
|
|
930
|
-
---
|
|
931
|
-
|
|
932
|
-
### `Field`
|
|
933
|
-
|
|
934
|
-
| Property | Type | Default | Required |
|
|
935
|
-
| ---------- | ------------------------------------------- | ------- | -------- |
|
|
936
|
-
| attributes | [`FieldAttributes`](#FieldAttributes) | _none_ | ✔️ |
|
|
937
|
-
| id | `string` | _none_ | ✔️ |
|
|
938
|
-
| type | [`EntityType.VISITORS_FIELDS`](#EntityType) | _none_ | ✔️ |
|
|
939
|
-
|
|
940
|
-
---
|
|
941
|
-
|
|
942
|
-
### `FieldAttributes`
|
|
943
|
-
|
|
944
|
-
| Property | Type | Default | Required |
|
|
945
|
-
| ----------- | ------------------- | ------- | -------- |
|
|
946
|
-
| created_at | `string` | _none_ | ✔️ |
|
|
947
|
-
| key | `string` | _none_ | ✔️ |
|
|
948
|
-
| name | `string` | _none_ | ✔️ |
|
|
949
|
-
| whitelisted | `boolean` \| `null` | _none_ | ✔️ |
|
|
950
|
-
|
|
951
|
-
---
|
|
952
|
-
|
|
953
|
-
### `FormResponse`
|
|
954
|
-
|
|
955
|
-
| Property | Type | Default | Required |
|
|
956
|
-
| ---------- | --------------------------------------------------- | ------- | -------- |
|
|
957
|
-
| attributes | [`FormResponseAttributes`](#FormResponseAttributes) | _none_ | ✔️ |
|
|
958
|
-
| id | `string` | _none_ | ✔️ |
|
|
959
|
-
| type | [`EntityType.EVENTS`](#EntityType) | _none_ | ✔️ |
|
|
960
|
-
|
|
961
|
-
---
|
|
962
|
-
|
|
963
|
-
### `FormResponseAttributes`
|
|
964
|
-
|
|
965
|
-
| Property | Type | Default | Required |
|
|
966
|
-
| -------- | --------------------------------------- | ------- | -------- |
|
|
967
|
-
| data | [`FormResponseData`](#FormResponseData) | _none_ | ✔️ |
|
|
968
|
-
| uuid | `string` | _none_ | ✔️ |
|
|
969
|
-
|
|
970
|
-
---
|
|
971
|
-
|
|
972
|
-
### `FormResponseData`
|
|
973
|
-
|
|
974
|
-
| Property | Type | Default | Required |
|
|
975
|
-
| -------- | ------------------------------- | ------- | -------- |
|
|
976
|
-
| browser | [`BrowserData`](#BrowserData) | _none_ | ✔️ |
|
|
977
|
-
| date | `string` | _none_ | ✔️ |
|
|
978
|
-
| details | `{ [key: string]: any }` | _none_ | ✔️ |
|
|
979
|
-
| fields | `{ [key: string]: any }` | _none_ | ✔️ |
|
|
980
|
-
| id | `string` | _none_ | ✔️ |
|
|
981
|
-
| identity | [`IdentityData`](#IdentityData) | _none_ | ✔️ |
|
|
982
|
-
| ip | `string` | _none_ | ✔️ |
|
|
983
|
-
| location | [`LocationData`](#LocationData) | _none_ | ✔️ |
|
|
984
|
-
| page | [`PageData`](#PageData) | _none_ | ✔️ |
|
|
985
|
-
| site | `string` | _none_ | ✔️ |
|
|
986
|
-
| type | `string` | _none_ | ✔️ |
|
|
987
|
-
| visit | `string` | _none_ | ✔️ |
|
|
988
|
-
| visitor | `string` | _none_ | ✔️ |
|
|
989
|
-
|
|
990
|
-
---
|
|
991
|
-
|
|
992
|
-
### `GetSubscribersParameters`
|
|
993
|
-
|
|
994
|
-
Note that this takes either `email` _or_ `uuid`, but never both.
|
|
995
|
-
|
|
996
|
-
| Property | Type | Default | Required |
|
|
997
|
-
| -------- | -------- | ------- | -------- |
|
|
998
|
-
| email | `string` | _none_ | ✔️ |
|
|
999
|
-
|
|
1000
|
-
| Property | Type | Default | Required |
|
|
1001
|
-
| -------- | -------- | ------- | -------- |
|
|
1002
|
-
| uuid | `string` | _none_ | ✔️ |
|
|
1003
|
-
|
|
1004
|
-
---
|
|
1005
|
-
|
|
1006
|
-
### `GeolocateParameters`
|
|
1007
|
-
|
|
1008
|
-
| Property | Type | Default | Required |
|
|
1009
|
-
| -------- | -------- | ------- | -------- |
|
|
1010
|
-
| ip | `string` | _none_ | ✔️ |
|
|
1011
|
-
|
|
1012
|
-
---
|
|
1013
|
-
|
|
1014
|
-
### `GuessGenderParameters`
|
|
1015
|
-
|
|
1016
|
-
| Property | Type | Default | Required |
|
|
1017
|
-
| -------- | -------- | ------- | -------- |
|
|
1018
|
-
| name | `string` | _none_ | ✔️ |
|
|
1019
|
-
|
|
1020
|
-
---
|
|
1021
|
-
|
|
1022
|
-
### `GuessGenderResponse`
|
|
1023
|
-
|
|
1024
|
-
| Property | Type | Default | Required |
|
|
1025
|
-
| ---------- | ------------------ | ------- | -------- |
|
|
1026
|
-
| confidence | `number` \| `null` | _none_ | ✔️ |
|
|
1027
|
-
| gender | `string` \| `null` | _none_ | ✔️ |
|
|
1028
|
-
|
|
1029
|
-
---
|
|
1030
|
-
|
|
1031
|
-
### `IdentityData`
|
|
1032
|
-
|
|
1033
|
-
| Property | Type | Default | Required |
|
|
1034
|
-
| -------- | -------- | ------- | -------- |
|
|
1035
|
-
| email | `string` | _none_ | ✔️ |
|
|
1036
|
-
|
|
1037
|
-
---
|
|
1038
|
-
|
|
1039
|
-
### `LocationData`
|
|
1040
|
-
|
|
1041
|
-
| Property | Type | Default | Required |
|
|
1042
|
-
| ---------------- | -------- | ------- | -------- |
|
|
1043
|
-
| city_name | `string` | _none_ | ❌ |
|
|
1044
|
-
| continent_code | `string` | _none_ | ❌ |
|
|
1045
|
-
| country_code2 | `string` | _none_ | ❌ |
|
|
1046
|
-
| country_code3 | `string` | _none_ | ❌ |
|
|
1047
|
-
| country_name | `string` | _none_ | ❌ |
|
|
1048
|
-
| ip | `string` | _none_ | ❌ |
|
|
1049
|
-
| latitude | `number` | _none_ | ❌ |
|
|
1050
|
-
| longitude | `number` | _none_ | ❌ |
|
|
1051
|
-
| postal_code | `string` | _none_ | ❌ |
|
|
1052
|
-
| real_region_name | `string` | _none_ | ❌ |
|
|
1053
|
-
| region_name | `string` | _none_ | ❌ |
|
|
1054
|
-
| request | `string` | _none_ | ❌ |
|
|
1055
|
-
|
|
1056
|
-
---
|
|
1057
|
-
|
|
1058
|
-
### `PageData`
|
|
1059
|
-
|
|
1060
|
-
| Property | Type | Default | Required |
|
|
1061
|
-
| -------- | -------- | ------- | -------- |
|
|
1062
|
-
| host | `string` | _none_ | ✔️ |
|
|
1063
|
-
| path | `string` | _none_ | ✔️ |
|
|
1064
|
-
| protocol | `string` | _none_ | ✔️ |
|
|
1065
|
-
| referrer | `string` | _none_ | ✔️ |
|
|
1066
|
-
| url | `string` | _none_ | ✔️ |
|
|
1067
|
-
|
|
1068
|
-
---
|
|
1069
|
-
|
|
1070
|
-
### `PurchaseCart`
|
|
1071
|
-
|
|
1072
|
-
| Property | Type | Default | Required |
|
|
1073
|
-
| ---------------------- | --------------------------------- | ------- | -------- |
|
|
1074
|
-
| abandoned_checkout_url | `string` | _none_ | ❌ |
|
|
1075
|
-
| items | [`PurchaseItem[]`](#PurchaseItem) | _none_ | ❌ |
|
|
1076
|
-
|
|
1077
|
-
---
|
|
1078
|
-
|
|
1079
|
-
### `PurchaseDetails`
|
|
1080
|
-
|
|
1081
|
-
| Property | Type | Default | Required |
|
|
1082
|
-
| -------- | --------------------------------------- | ------- | -------- |
|
|
1083
|
-
| unique | `{ key: string \| number; }` | _none_ | ✔️ |
|
|
1084
|
-
| value | `{ currency: string; amount: number; }` | _none_ | ✔️ |
|
|
1085
|
-
| cart | [`PurchaseCart`](#PurchaseCart) | _none_ | ❌ |
|
|
1086
|
-
|
|
1087
|
-
---
|
|
1088
|
-
|
|
1089
|
-
### `PurchaseItem`
|
|
1090
|
-
|
|
1091
|
-
In addition to the properties below, you can pass any other properties that you want as part of the `PurchaseItem`.
|
|
1092
|
-
|
|
1093
|
-
| Property | Type | Default | Required |
|
|
1094
|
-
| ------------- | -------- | ------- | -------- |
|
|
1095
|
-
| product_sku | `string` | _none_ | ❌ |
|
|
1096
|
-
| product_name | `string` | _none_ | ❌ |
|
|
1097
|
-
| quantity | `number` | _none_ | ❌ |
|
|
1098
|
-
| product_price | `number` | _none_ | ❌ |
|
|
1099
|
-
| product_id | `string` | _none_ | ❌ |
|
|
1100
|
-
|
|
1101
|
-
---
|
|
1102
|
-
|
|
1103
|
-
### `RemoveFieldParameters<S>`
|
|
1104
|
-
|
|
1105
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
1106
|
-
|
|
1107
|
-
| Property | Type | Default | Required |
|
|
1108
|
-
| --------- | --------- | ------- | -------- |
|
|
1109
|
-
| email | `string` | _none_ | ✔️ |
|
|
1110
|
-
| fieldName | `keyof S` | _none_ | ✔️ |
|
|
1111
|
-
|
|
1112
|
-
---
|
|
1113
|
-
|
|
1114
|
-
### `RemoveSubscriberParameters`
|
|
1115
|
-
|
|
1116
|
-
| Property | Type | Default | Required |
|
|
1117
|
-
| -------- | -------- | ------- | -------- |
|
|
1118
|
-
| date | `Date` | _none_ | ❌ |
|
|
1119
|
-
| email | `string` | _none_ | ✔️ |
|
|
609
|
+
### Sequences
|
|
610
|
+
|
|
611
|
+
Retrieve sequences and their associated email templates.
|
|
612
|
+
|
|
613
|
+
#### getSequences
|
|
614
|
+
|
|
615
|
+
Retrieves all sequences for the site, including their email templates.
|
|
616
|
+
|
|
617
|
+
```javascript
|
|
618
|
+
const sequences = await bento.V1.Sequences.getSequences();
|
|
619
|
+
// Returns:
|
|
620
|
+
// [
|
|
621
|
+
// {
|
|
622
|
+
// id: '123',
|
|
623
|
+
// type: 'sequence',
|
|
624
|
+
// attributes: {
|
|
625
|
+
// name: 'Welcome Sequence',
|
|
626
|
+
// created_at: '2024-01-01T00:00:00Z',
|
|
627
|
+
// email_templates: [
|
|
628
|
+
// { id: 1, subject: 'Welcome!', stats: null },
|
|
629
|
+
// { id: 2, subject: 'Getting Started', stats: null }
|
|
630
|
+
// ]
|
|
631
|
+
// }
|
|
632
|
+
// }
|
|
633
|
+
// ]
|
|
634
|
+
```
|
|
1120
635
|
|
|
1121
|
-
|
|
636
|
+
### Workflows
|
|
637
|
+
|
|
638
|
+
Retrieve workflows and their associated email templates.
|
|
639
|
+
|
|
640
|
+
#### getWorkflows
|
|
641
|
+
|
|
642
|
+
Retrieves all workflows for the site, including their email templates.
|
|
643
|
+
|
|
644
|
+
```javascript
|
|
645
|
+
const workflows = await bento.V1.Workflows.getWorkflows();
|
|
646
|
+
// Returns:
|
|
647
|
+
// [
|
|
648
|
+
// {
|
|
649
|
+
// id: '456',
|
|
650
|
+
// type: 'workflow',
|
|
651
|
+
// attributes: {
|
|
652
|
+
// name: 'Onboarding Workflow',
|
|
653
|
+
// created_at: '2024-01-01T00:00:00Z',
|
|
654
|
+
// email_templates: [
|
|
655
|
+
// { id: 3, subject: 'Step 1', stats: null },
|
|
656
|
+
// { id: 4, subject: 'Step 2', stats: null }
|
|
657
|
+
// ]
|
|
658
|
+
// }
|
|
659
|
+
// }
|
|
660
|
+
// ]
|
|
661
|
+
```
|
|
1122
662
|
|
|
1123
|
-
###
|
|
663
|
+
### Email Templates
|
|
1124
664
|
|
|
1125
|
-
|
|
1126
|
-
| -------- | -------- | ------- | -------- |
|
|
1127
|
-
| email | `string` | _none_ | ✔️ |
|
|
1128
|
-
| tagName | `string` | _none_ | ✔️ |
|
|
665
|
+
Retrieve and update email templates used in sequences and workflows.
|
|
1129
666
|
|
|
1130
|
-
|
|
667
|
+
#### getEmailTemplate
|
|
1131
668
|
|
|
1132
|
-
|
|
669
|
+
Retrieves a single email template by ID.
|
|
1133
670
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
671
|
+
```javascript
|
|
672
|
+
const template = await bento.V1.EmailTemplates.getEmailTemplate({ id: 123 });
|
|
673
|
+
// Returns:
|
|
674
|
+
// {
|
|
675
|
+
// id: '123',
|
|
676
|
+
// type: 'email_template',
|
|
677
|
+
// attributes: {
|
|
678
|
+
// name: 'Welcome Email',
|
|
679
|
+
// subject: 'Welcome to our service!',
|
|
680
|
+
// html: '<p>Hello {{ name }}, welcome!</p>',
|
|
681
|
+
// created_at: '2024-01-01T00:00:00Z',
|
|
682
|
+
// stats: null
|
|
683
|
+
// }
|
|
684
|
+
// }
|
|
685
|
+
```
|
|
1137
686
|
|
|
1138
|
-
|
|
687
|
+
#### updateEmailTemplate
|
|
1139
688
|
|
|
1140
|
-
|
|
689
|
+
Updates an email template's subject and/or HTML content.
|
|
1141
690
|
|
|
1142
|
-
|
|
691
|
+
```javascript
|
|
692
|
+
const updatedTemplate = await bento.V1.EmailTemplates.updateEmailTemplate({
|
|
693
|
+
id: 123,
|
|
694
|
+
subject: 'Updated Subject Line',
|
|
695
|
+
html: '<p>Updated HTML content with {{ name }}</p>',
|
|
696
|
+
});
|
|
697
|
+
```
|
|
1143
698
|
|
|
1144
|
-
|
|
1145
|
-
| ---------- | --------------------------------------------------- | ------- | -------- |
|
|
1146
|
-
| attributes | [`SubscriberAttributes<S>`](#subscriberattributess) | _none_ | ✔️ |
|
|
1147
|
-
| id | `string` | _none_ | ✔️ |
|
|
1148
|
-
| type | [`EntityType.VISITOR`](#EntityType) | _none_ | ✔️ |
|
|
699
|
+
For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
|
|
1149
700
|
|
|
1150
|
-
|
|
701
|
+
## Types Reference
|
|
1151
702
|
|
|
1152
|
-
|
|
703
|
+
This section provides a detailed reference for the types used in the Bento Node.js SDK.
|
|
704
|
+
AddFieldParameters `<S>`
|
|
1153
705
|
|
|
1154
|
-
|
|
1155
|
-
| --------------- | ------------- | ------- | -------- |
|
|
1156
|
-
| cached_tag_ids | `string[]` | _none_ | ✔️ |
|
|
1157
|
-
| email | `string` | _none_ | ✔️ |
|
|
1158
|
-
| fields | `S` \| `null` | _none_ | ✔️ |
|
|
1159
|
-
| unsubscribed_at | `string` | _none_ | ✔️ |
|
|
1160
|
-
| uuid | `string` | _none_ | ✔️ |
|
|
706
|
+
Parameters for adding a field to a subscriber.
|
|
1161
707
|
|
|
1162
|
-
|
|
708
|
+
| Property | Type | Required | Description |
|
|
709
|
+
| -------- | ---------------------------- | -------- | -------------------------- |
|
|
710
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
711
|
+
| field | { key: keyof S; value: any } | ✔️ | Field to add |
|
|
1163
712
|
|
|
1164
|
-
|
|
1165
|
-
| ------------ | ------------------ | ------- | -------- |
|
|
1166
|
-
| created_at | `string` | _none_ | ✔️ |
|
|
1167
|
-
| discarded_at | `string` \| `null` | _none_ | ✔️ |
|
|
1168
|
-
| name | `string` \| `null` | _none_ | ✔️ |
|
|
1169
|
-
| site_id | `string` | _none_ | ✔️ |
|
|
713
|
+
### AddSubscriberParameters `<S>`
|
|
1170
714
|
|
|
1171
|
-
|
|
715
|
+
Parameters for adding a new subscriber.
|
|
1172
716
|
|
|
1173
|
-
|
|
717
|
+
| Property | Type | Required | Description |
|
|
718
|
+
| -------- | ------------- | -------- | ------------------------------------ |
|
|
719
|
+
| date | Date | ❌ | Date of subscription |
|
|
720
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
721
|
+
| fields | Partial `<S>` | ❌ | Additional fields for the subscriber |
|
|
1174
722
|
|
|
1175
|
-
|
|
1176
|
-
| ---------- | --------------------------------- | ------- | -------- |
|
|
1177
|
-
| attributes | [`TagAttributes`](#TagAttributes) | _none_ | ✔️ |
|
|
1178
|
-
| id | `string` | _none_ | ✔️ |
|
|
1179
|
-
| type | [`EntityType.TAG`](#EntityType) | _none_ | ✔️ |
|
|
723
|
+
### AddTagParameters
|
|
1180
724
|
|
|
1181
|
-
|
|
725
|
+
Parameters for adding a tag to a subscriber.
|
|
1182
726
|
|
|
1183
|
-
|
|
727
|
+
| Property | Type | Required | Description |
|
|
728
|
+
| -------- | ------ | -------- | -------------------------- |
|
|
729
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
730
|
+
| tagName | string | ✔️ | Name of the tag to add |
|
|
1184
731
|
|
|
1185
|
-
|
|
1186
|
-
| -------- | -------- | ------- | -------- |
|
|
1187
|
-
| date | `Date` | _none_ | ❌ |
|
|
1188
|
-
| email | `string` | _none_ | ✔️ |
|
|
1189
|
-
| tagName | `string` | _none_ | ✔️ |
|
|
732
|
+
### BatchImportEventsParameter `<S>`, `<E>`
|
|
1190
733
|
|
|
1191
|
-
|
|
734
|
+
Parameters for batch importing events.
|
|
1192
735
|
|
|
1193
|
-
|
|
736
|
+
| Property | Type | Required | Description |
|
|
737
|
+
| -------- | ----------------------- | -------- | ------------------------- |
|
|
738
|
+
| events | BentoEvent `<S>`, `<E>` | ✔️ | Array of events to import |
|
|
1194
739
|
|
|
1195
|
-
|
|
740
|
+
### BatchImportSubscribersParameter `<S>`
|
|
1196
741
|
|
|
1197
|
-
|
|
742
|
+
Parameters for batch importing subscribers.
|
|
1198
743
|
|
|
1199
|
-
| Property
|
|
1200
|
-
|
|
|
1201
|
-
|
|
|
1202
|
-
| type | `string` | _none_ | ✔️ |
|
|
1203
|
-
| details | `{ [key: string]: any }` | _none_ | ❌ |
|
|
1204
|
-
| fields | `Partial<S>` | _none_ | ❌ |
|
|
744
|
+
| Property | Type | Required | Description |
|
|
745
|
+
| ----------- | ------------------------------------- | -------- | ------------------------------ |
|
|
746
|
+
| subscribers | ({ email: string } & Partial `<S>`)[] | ✔️ | Array of subscribers to import |
|
|
1205
747
|
|
|
1206
|
-
|
|
748
|
+
### BentoEvent `<S>`, `<E>`
|
|
1207
749
|
|
|
1208
|
-
|
|
750
|
+
Represents different types of events in Bento. It's a union of the following event types:
|
|
1209
751
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
752
|
+
- BaseEvent `<E>`
|
|
753
|
+
- PurchaseEvent
|
|
754
|
+
- SubscribeEvent `<S>`
|
|
755
|
+
- TagEvent
|
|
756
|
+
- UnsubscribeEvent
|
|
757
|
+
- UpdateFieldsEvent `<S>`
|
|
1215
758
|
|
|
1216
|
-
|
|
759
|
+
### PurchaseDetails
|
|
1217
760
|
|
|
1218
|
-
|
|
761
|
+
Details of a purchase event.
|
|
1219
762
|
|
|
1220
|
-
| Property | Type
|
|
1221
|
-
| -------- |
|
|
1222
|
-
|
|
|
763
|
+
| Property | Type | Required | Description |
|
|
764
|
+
| -------- | ------------------------------------ | -------- | ---------------------------------- |
|
|
765
|
+
| unique | { key: string \| number } | ✔️ | Unique identifier for the purchase |
|
|
766
|
+
| value | { currency: string; amount: number } | ✔️ | Value of the purchase |
|
|
767
|
+
| cart | PurchaseCart | ❌ | Additional cart details |
|
|
1223
768
|
|
|
1224
|
-
|
|
769
|
+
### ChangeEmailParameters
|
|
1225
770
|
|
|
1226
|
-
|
|
771
|
+
Parameters for changing a subscriber's email.
|
|
1227
772
|
|
|
1228
|
-
|
|
773
|
+
| Property | Type | Required | Description |
|
|
774
|
+
| -------- | ------ | -------- | --------------------- |
|
|
775
|
+
| oldEmail | string | ✔️ | Current email address |
|
|
776
|
+
| newEmail | string | ✔️ | New email address |
|
|
1229
777
|
|
|
1230
|
-
|
|
1231
|
-
| -------- | ------------ | ------- | -------- |
|
|
1232
|
-
| date | `Date` | _none_ | ❌ |
|
|
1233
|
-
| email | `string` | _none_ | ✔️ |
|
|
1234
|
-
| fields | `Partial<S>` | _none_ | ✔️ |
|
|
778
|
+
### CreateFieldParameters
|
|
1235
779
|
|
|
1236
|
-
|
|
780
|
+
Parameters for creating a new field.
|
|
1237
781
|
|
|
1238
|
-
|
|
782
|
+
| Property | Type | Required | Description |
|
|
783
|
+
| -------- | ------ | -------- | -------------------- |
|
|
784
|
+
| key | string | ✔️ | Key of the new field |
|
|
1239
785
|
|
|
1240
|
-
|
|
1241
|
-
| --------- | -------- | ------- | -------- |
|
|
1242
|
-
| email | `string` | _none_ | ✔️ |
|
|
1243
|
-
| ip | `string` | _none_ | ❌ |
|
|
1244
|
-
| name | `string` | _none_ | ❌ |
|
|
1245
|
-
| userAgent | `string` | _none_ | ❌ |
|
|
786
|
+
### CreateTagParameters
|
|
1246
787
|
|
|
1247
|
-
|
|
788
|
+
Parameters for creating a new tag.
|
|
1248
789
|
|
|
1249
|
-
|
|
790
|
+
| Property | Type | Required | Description |
|
|
791
|
+
| -------- | ------ | -------- | ------------------- |
|
|
792
|
+
| name | string | ✔️ | Name of the new tag |
|
|
1250
793
|
|
|
1251
|
-
###
|
|
794
|
+
### Subscriber `<S>`
|
|
1252
795
|
|
|
1253
|
-
|
|
796
|
+
Represents a subscriber in Bento.
|
|
1254
797
|
|
|
1255
|
-
|
|
798
|
+
| Property | Type | Required | Description |
|
|
799
|
+
| ---------- | -------------------------- | -------- | ---------------------------- |
|
|
800
|
+
| attributes | SubscriberAttributes `<S>` | ✔️ | Attributes of the subscriber |
|
|
801
|
+
| id | string | ✔️ | Unique identifier |
|
|
802
|
+
| type | EntityType.VISITOR | ✔️ | Type of the entity |
|
|
1256
803
|
|
|
1257
|
-
|
|
804
|
+
### TrackParameters `<S>`, `<E>`
|
|
1258
805
|
|
|
1259
|
-
|
|
1260
|
-
type MySubscriberFields = {
|
|
1261
|
-
firstName: string;
|
|
1262
|
-
lastName: string;
|
|
1263
|
-
age: number;
|
|
1264
|
-
};
|
|
806
|
+
Parameters for tracking an event.
|
|
1265
807
|
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
808
|
+
| Property | Type | Required | Description |
|
|
809
|
+
| -------- | ---------------------- | -------- | ----------------------------------- |
|
|
810
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
811
|
+
| type | string | ✔️ | Type of the event |
|
|
812
|
+
| details | { [key: string]: any } | ❌ | Additional details of the event |
|
|
813
|
+
| fields | Partial `<S>` | ❌ | Fields to update for the subscriber |
|
|
1270
814
|
|
|
1271
|
-
|
|
815
|
+
### ValidateEmailParameters
|
|
1272
816
|
|
|
1273
|
-
|
|
817
|
+
Parameters for validating an email address.
|
|
1274
818
|
|
|
1275
|
-
|
|
819
|
+
| Property | Type | Required | Description |
|
|
820
|
+
| --------- | ------ | -------- | ------------------------------ |
|
|
821
|
+
| email | string | ✔️ | Email address to validate |
|
|
822
|
+
| ip | string | ❌ | IP address of the user |
|
|
823
|
+
| name | string | ❌ | Name associated with the email |
|
|
824
|
+
| userAgent | string | ❌ | User agent string |
|
|
1276
825
|
|
|
1277
|
-
|
|
1278
|
-
const bento = new Analytics<any, '$myPrefix.'>({
|
|
1279
|
-
// ... initialization options from above.
|
|
1280
|
-
});
|
|
1281
|
-
```
|
|
826
|
+
Note: The `S` and `E` generic types are used for TypeScript support. `S` represents the type of your subscriber's custom fields, and `E` represents the prefix used for custom events. For more details, refer to the TypeScript section of the documentation.
|
|
1282
827
|
|
|
1283
828
|
## Things to know
|
|
1284
829
|
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
830
|
+
- All events must be identified with an email address.
|
|
831
|
+
- Most events are indexed within seconds in your Bento account.
|
|
832
|
+
- The SDK supports TypeScript with generics for custom fields and events.
|
|
833
|
+
- Batch operations are available for importing subscribers and events efficiently.
|
|
834
|
+
- The SDK doesn't currently support anonymous events (coming soon).
|
|
835
|
+
- Requests have a default timeout of 30 seconds, configurable via `clientOptions.timeout`.
|
|
836
|
+
|
|
837
|
+
## Error Handling
|
|
838
|
+
|
|
839
|
+
The SDK exports several error types for specific error conditions:
|
|
840
|
+
|
|
841
|
+
```javascript
|
|
842
|
+
import {
|
|
843
|
+
NotAuthorizedError, // 401 - Invalid credentials
|
|
844
|
+
RateLimitedError, // 429 - Too many requests
|
|
845
|
+
AuthorNotAuthorizedError, // Author not permitted to send emails
|
|
846
|
+
RequestTimeoutError, // Request exceeded timeout
|
|
847
|
+
} from '@bentonow/bento-node-sdk';
|
|
848
|
+
|
|
849
|
+
try {
|
|
850
|
+
await bento.V1.Tags.getTags();
|
|
851
|
+
} catch (error) {
|
|
852
|
+
if (error instanceof RequestTimeoutError) {
|
|
853
|
+
// Handle timeout - maybe retry
|
|
854
|
+
} else if (error instanceof RateLimitedError) {
|
|
855
|
+
// Handle rate limiting - back off and retry
|
|
856
|
+
} else if (error instanceof NotAuthorizedError) {
|
|
857
|
+
// Handle auth error - check credentials
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
```
|
|
1288
861
|
|
|
1289
862
|
## Contributing
|
|
1290
863
|
|
|
1291
|
-
|
|
864
|
+
We welcome contributions! Please see our [contributing guidelines](CODE_OF_CONDUCT.md) for details on how to submit pull requests, report issues, and suggest improvements.
|
|
1292
865
|
|
|
1293
866
|
## License
|
|
1294
867
|
|
|
1295
|
-
The
|
|
868
|
+
The Bento SDK for Node.js is available as open source under the terms of the [MIT License](LICENSE.md).
|