Import customers contacts from OFN to newsletter

These workflows allow to export customers info from OFN and import them into one of these newsletter tools: Mailjet, Sendinblue or Mailchimp.

How to use it?

You can import the templates in N8N, then follow the step-by-step instructions displayed in the workflows:

⚠️ For the Sendinblue node, depending on your language, you will have to change the "attributes" names in the query parameters of node 6 (for instance ). Please also note that these attributes names can be changed by the users. If it's the case, the request will fail (it was the same in Zapier).

Ex of request for EN accounts:

{{ { 
"email":$json.email, 
"ext_id":"", 
"attributes":
{ 
"FNAME":$json.lastName,
"LNAME":$json.firstName,
"SMS":"+33" + $json.phone.substring(1) 
}, 
"emailBlacklisted":false, "smsBlacklisted":false, 
"listIds":[$json.id], 
"updateEnabled":true, "smtpBlacklistSender":[""] 
} 
}}

Ex of request for FR accounts:

{{ { 
"email":$json.email, 
"ext_id":"", 
"attributes":
{ 
"NOM":$json.lastName,
"PRENOM":$json.firstName,
"SMS":"+33" + $json.phone.substring(1) 
}, 
"emailBlacklisted":false, "smsBlacklisted":false, 
"listIds":[$json.id], 
"updateEnabled":true, "smtpBlacklistSender":[""] 
} 
}}

How does it work?

The workflow can be divided in 2 main parts:

  • Getting customers info from OFN:

A call is made to the API V1, with the enterprise credentials and the shop ID as query parameter, to get the list of customers and their info.

GET https://coopcircuits.fr/api/v1/customers

As the hard limit of returned customers is 200, there is an iteration through the pages (the two "IF" nodes), until all customers are returned.

  • Importing customers info the newsletter tool:

The process is slightly different for each newsletter tool:

  • Sendinblue:

As there's no N8N Sendinblue node yet, the calls are made manually to Sendinblue API with HTTP nodes.

  • The workflow allows to create a list first. In order to achieve this, we need to get the Sendinblue folder ID (Node 1) and then create the contact list in this folder (Node 2). The 2 calls are the following:

GET https://api.sendinblue.com/v3/contacts/folders

POST https://api.sendinblue.com/v3/contacts/lists

After playing these 2 nodes, the admin can copy the list ID and paste it into Node 3.A. (i tried to automatize this but it's not possible to "save" data between execution in N8N - see this thread).

  • Next step is importing customers in the list: As there's no upsert (add or update) request, the workflow first does a GET request to Sendinblue, to get all existing customers.

GET https://api.sendinblue.com/v3/contacts?limit=500&sort=desc

As there's a hard limit of 500 customers per request, there is an iteration through the items until all customers are returned. There's no concept of "page" but instead there's an "offset", which defines from which item the request will return elements. In our case we loop as following: first iteration with an offset=0, second iteration with an offset = 500, etc.

Then the list of existing customers is compared to the OFN one, based on the emails, and only new contacts are kept.

Finally a call imports all these new customers into the Sendinblue list. Query parameters include the contact email and the "attributes" (⚠️ the attributes names depend on the language - in EN it would be FNAME, LNAME - can be changed by the admin - for instance)

There's a "Split in Batches" node beforehand because Sendinblue would return an error if you send too many customers at once.

POST https://api.sendinblue.com/v3/contacts/

{{ { 
"email":$json.email, 
"ext_id":"", 
"attributes":
{ 
"NOM":$json.lastName,
"PRENOM":$json.firstName,
"SMS":"+33" + $json.phone.substring(1) 
}, 
"emailBlacklisted":false, "smsBlacklisted":false, 
"listIds":[$json.id], 
"updateEnabled":true, "smtpBlacklistSender":[""] 
} 
}}

In the provided templates the fields that are imported are:

  • Email

  • First name

  • Last name

  • Phone

  • Mailjet:

The first node allows to create a list in Mailjet. After playing this node, the admin can copy the list ID and paste it into the query URL in Node 4. (i tried to automatize this but it's not possible to "save" data between execution in N8N - see this thread).

The last node is the import made in Maijet. The whole contact list is passed in one time.

POST https://api.mailjet.com/v3/REST/contactslist/LIST_ID_HERE/managemanycontacts

In the provided templates the fields that are imported are:

  • Email

  • Mailchimp:

In N8N there's a Mailchimp node, but the "Add/update" action doesn't exist (request posted here, please upvote).

Thus the workflow is first getting the contacts list in a specific list in Mailchimp (node 3). Note that when you choose the user Mailchimp credentials, its lists will be displayed - it's useful so we don't have to create a list.

Then the list of existing customers is compared to the OFN one, based on the emails, and only new contacts are kept.

These contacts are added to Mailchimp thanks to node "4. Mailchimp Create". There's a "Split in Batches" node beforehand because Mailchimp sometimes dont like too many request at once.

In the provided templates the fields that are imported are:

  • Email

  • First name

  • Last name

  • Phone

  • Address

  • Workflow Automation

In all 3 workflows there's a "Schedule trigger" node that will play the workflow at the defined frequency.

Last updated