Skip to content

Commit 3bad95e

Browse files
Merge pull request #64 from getbrevo/feature_update-documentation-v3-brevo-node_COAPI-0
COAPI-0 Update Readme.md
2 parents b3d064c + 9b93dc6 commit 3bad95e

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,131 @@ contactAPI.createContact(contact).then(res => {
225225
});
226226
```
227227

228+
# Concerning v3.0.0 and above:
229+
> [!IMPORTANT]
230+
> There has been a change in the usage of this library after v3.0.0 which is not backward compatible.
231+
232+
### Installation
233+
234+
```npm i @getbrevo/brevo --save```
235+
236+
### Import packages
237+
238+
```import { CreateContact, ContactsApi } from "@getbrevo/brevo";```
239+
240+
### Instantiate API with your credentials
241+
242+
```
243+
let contactAPI = new ContactsApi();
244+
(contactAPI as any).authentications.apiKey.apiKey = "xkeysib-xxxxxxxxx";
245+
```
246+
247+
### Build your contact
248+
249+
```let contact = new CreateContact();
250+
contact.email = "michael.brown@example.com";
251+
contact.attributes = {
252+
FIRSTNAME: { value: "Michael" },
253+
LASTNAME: { value: "Brown" }
254+
};
255+
```
256+
257+
### Create the contact
258+
259+
```contactAPI.createContact(contact).then(res => {
260+
console.log(JSON.stringify(res.body));
261+
}).catch(err => {
262+
console.error("Error creating contact:", err.body);
263+
});
264+
```
265+
266+
### Similar other examples:
267+
268+
```typescript
269+
270+
import { TransactionalEmailsApi, TransactionalEmailsApiApiKeys } from '@getbrevo/brevo';
271+
272+
const transactionalEmailsApi = new TransactionalEmailsApi();
273+
transactionalEmailsApi.setApiKey(TransactionalEmailsApiApiKeys.apiKey, 'xkeysib-API_KEY');
274+
275+
async function sendTransactionalEmail() {
276+
try {
277+
const result = await transactionalEmailsApi.sendTransacEmail({
278+
to: [
279+
{ email: 'sampleemail@gmail.com', name: 'John doe' },
280+
],
281+
subject: 'Hello from Brevo SDK!',
282+
htmlContent: '<h1>This is a transactional email sent using the Brevo SDK.</h1>',
283+
textContent: 'This is a transactional email sent using the Brevo SDK.',
284+
sender: { email: 'sampleemail@gmail.com', name: 'John doe' },
285+
});
286+
console.log('Email sent! Message ID:', result.body.messageId);
287+
} catch (error) {
288+
console.error('Failed to send email:', error);
289+
}
290+
}
291+
292+
sendTransactionalEmail();
293+
```
294+
295+
```typescript
296+
297+
import { DealsApi, DealsApiApiKeys } from '@getbrevo/brevo';
298+
299+
const dealsApi = new DealsApi();
300+
dealsApi.setApiKey(DealsApiApiKeys.apiKey, 'xkeysib-YOUR_API_KEY');
301+
302+
async function getDeals() {
303+
try {
304+
const response = await dealsApi.crmDealsGet()
305+
console.log('Deals info:', response.body);
306+
} catch (error) {
307+
console.error('Failed to get account info:', error);
308+
}
309+
}
310+
311+
getDeals();
312+
```
313+
314+
```typescript
315+
316+
import { AccountApi, AccountApiApiKeys } from '@getbrevo/brevo';
317+
318+
const accountApi = new AccountApi();
319+
accountApi.setApiKey(AccountApiApiKeys.apiKey, 'xkeysib-YOUR_API_KEY');
320+
321+
async function getAccount() {
322+
try {
323+
const response = await accountApi.getAccount();
324+
console.log('Account info:', response.body);
325+
} catch (error) {
326+
console.error('Failed to get account info:', error);
327+
}
328+
}
329+
330+
getAccount();
331+
```
332+
333+
```typescript
334+
335+
import { ContactsApi, ContactsApiApiKeys } from '@getbrevo/brevo';
336+
337+
const contactsApi = new ContactsApi();
338+
contactsApi.setApiKey(ContactsApiApiKeys.apiKey, 'xkeysib-YOUR_API_KEY');
339+
340+
async function getContacts(limit: number, offset: number) {
341+
try {
342+
const result = await contactsApi.getContacts(limit, offset);
343+
console.log('Contacts:', result.body);
344+
} catch (error) {
345+
console.error('Failed to get contacts:', error);
346+
}
347+
}
348+
349+
getContacts(10, 0); // Example: get first 10 contacts
350+
```
351+
352+
228353
## Support
229354

230355
For questions and support, please refer to our [documentation](https://developers.brevo.com) or contact our support team.

0 commit comments

Comments
 (0)