Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Create new node for Sendinblue API #2277

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/nodes-base/credentials/Sendinblue.credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';

export class Sendinblue implements ICredentialType {
name = 'sendinblue';
displayName = 'Sendinblue';
properties = [
{
displayName: 'API-Key',
name: 'apiKey',
type: 'string' as NodePropertyTypes,
default: '',
typeOptions: {
password: true,
},
description: 'The API-Key provided by Sendinblue',
},
];
}
138 changes: 138 additions & 0 deletions packages/nodes-base/nodes/Sendinblue/ContactDescription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {
INodeProperties,
} from 'n8n-workflow';

export const contactActions = [
{
displayName: 'Action',
name: 'action',
type: 'options',
displayOptions: {
show: {
apiResource: ['contacts'],
},
},
options: [
{
name: 'Create',
description: 'Create a contact',
value: 'create',
},
{
name: 'Get',
description: 'Get a contact\'s details',
value: 'get',
},
{
name: 'Update',
description: 'Update a contact',
value: 'update',
},
{
name: 'Delete',
description: 'Delete a contact',
value: 'delete',
},
/* @todo Get contacts in a list */
{
name: 'Add to list',
description: 'Add existing contact(s) to a list',
value: 'addToList',
},
{
name: 'Remove from list',
description: 'Remove existing contact(s) from a list',
value: 'removeFromList',
},
],
default: 'get',
},
] as INodeProperties[];

export const contactFields = [
{
displayName: 'eMail Address',
name: 'email',
type: 'string',
description: 'Email address of the contact.',
displayOptions: {
show: {
apiResource: ['contacts'],
action: ['create', 'get', 'update', 'delete'],
},
},
default: '',
required: true,
},
{
displayName: 'List ID',
name: 'listId',
type: 'number',
description: 'ID of the list',
displayOptions: {
show: {
apiResource: ['contacts'],
action: ['addToList', 'removeFromList'],
},
},
default: 1,
required: true,
},
{
displayName: 'eMail Addresses Property Name',
name: 'emailAddresses',
type: 'string',
description: 'Emails to add to a list. You can pass a maximum of 150 emails for addition in one request.',
displayOptions: {
show: {
'apiResource': ['contacts'],
'action': ['addToList', 'removeFromList'],
},
},
default: 'emails',
required: true,
},

] as INodeProperties[];

export const contactOptions = [
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
displayOptions: {
show: {
apiResource: ['contacts'],
},
},
options: [
{
displayName: 'Attributes Property Name',
name: 'attributes',
type: 'string',
description: 'Pass the set of attributes and their values. These attributes must be present in your SendinBlue account. For eg:\n' +
'{"FNAME":"Elly", "LNAME":"Roger"}',
displayOptions: {
show: {
'/action': ['create', 'update'],
},
},
default: 'attributes',
},
{
displayName: 'Update Enabled',
name: 'updateEnabled',
type: 'boolean',
description: 'Facilitate to update the existing contact in the same request (updateEnabled = true)',
displayOptions: {
show: {
'/action': ['create'],
},
},
default: false,
},
],
},
] as INodeProperties[];
127 changes: 127 additions & 0 deletions packages/nodes-base/nodes/Sendinblue/ContactListDescription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {INodeProperties} from 'n8n-workflow';

export const contactListActions = [
{
displayName: 'Action',
name: 'action',
type: 'options',
displayOptions: {
show: {
apiResource: ['contactLists'],
},
},
default: 'get',
options: [
{
name: 'Create',
description: 'Create a contact list',
value: 'create',
},
{
name: 'Get',
description: 'Get a contact list\'s details',
value: 'get',
},
/* @todo Get lists in a folder */
/* @todo Get all the lists */
{
name: 'Update',
description: 'Update a contact list',
value: 'update',
},
{
name: 'Delete',
description: 'Delete a contact list',
value: 'delete',
},
],
},
] as INodeProperties[];

export const contactListFields = [
{
displayName: 'List ID',
name: 'listId',
type: 'number',
description: 'ID of the list',
displayOptions: {
show: {
apiResource: ['contactLists'],
action: ['get', 'update', 'delete'],
},
},
default: '',
required: true,
},
{
displayName: 'List Name',
name: 'listName',
type: 'string',
description: 'Name of the list',
displayOptions: {
show: {
apiResource: ['contactLists'],
action: ['create'],
},
},
default: 'List',
required: true,
},
{
displayName: 'Folder ID',
name: 'folderId',
type: 'number',
description: 'ID of the list folder',
displayOptions: {
show: {
apiResource: ['contactLists'],
action: ['create'],
},
},
default: '',
required: true,
},
] as INodeProperties[];

export const contactListOptions = [
{
displayName: 'Options',
name: 'options',
placeholder: 'Add Option',
type: 'collection',
default: {},
displayOptions: {
show: {
apiResource: ['contactLists'],
},
},
options: [
{
displayName: 'List Name',
name: 'listName',
type: 'string',
description: 'Name of the list',
displayOptions: {
show: {
'/action': ['update'],
},
},
default: 'List',
required: false,
},
{
displayName: 'Folder ID',
name: 'folderId',
type: 'number',
description: 'ID of the list folder',
displayOptions: {
show: {
'/action': ['update'],
},
},
default: '',
required: false,
},
],
},
] as INodeProperties[];
45 changes: 45 additions & 0 deletions packages/nodes-base/nodes/Sendinblue/GenericFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
OptionsWithUri,
} from 'request';

import {
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';

import {
IContextObject,
IDataObject, NodeApiError,
} from 'n8n-workflow';

export async function sendinblueApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: IContextObject): Promise<any> { // tslint:disable-line:no-any
const credentials = await this.getCredentials('sendinblue') as IDataObject;
const apiUrl = 'https://api.sendinblue.com/v3/' + endpoint;

const options: OptionsWithUri = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'api-key': credentials.apiKey,
},
method,
body: method === 'GET' ? undefined : body,
uri: apiUrl,
json: true,
};

try {
try {
// @ts-ignore
return await this.helpers.request(options);
} catch (error) {
if (error.error.message.length > 0) {
throw new Error(`${error.statusCode} - ${error.error.message}`);
}
throw error;
}
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}
Loading