Creating Customers (with Tags) on OFN using V1 API with data from a CSV/XLSX file

Content for Google drive to be added soon

This workflow describes how to use customers API endpoint (V1) to create customers on Open Food Network with data from a csv/xlsx file received in email (alternative options: Google Drive /Nextcloud).

Customers API documentation can be found here: Customers

This workflow is set to run manually, instead of using a trigger or schedule. We can automate the workflow to run when you receive an email (with email filters) containing the required CSV file (in case its offered as an automated service/add on), but there doesn’t seem to be any significant advantage for it and we would need a list of API keys for different hubs to be stored somewhere to match with the Hub from the email, which doesn’t seem like a good idea.

Note:

  1. For this example, I am only adding customer name, email, and tags. Following the documentation for Customers API endpoint, you can add other customer details such as shipping and billing addresses.

  2. Multiple tags can be added to a customer by separating them with comma (,).

Modules in the workflow: Trigger: Manual Trigger Getting the file: Gmail/Google Drive/NextCloud module Reading the file data: Spreadsheet module Creating Customers on OFN: HTTP module

Gmail Module: This module searches through the connected gmail account to find an email matching the filter conditions. Operations field: Get Many (it will ask you for message id if you select Get a message option)

Limit: 1 Filters: Search: search for the email using filters in your gmail inbox and copy it over in the search box here or just edit the one below

Search Query: from:(sender email) subject:(email subject) has:attachment

Download attachment: Yes

Note: Check the output of this node before running the whole workflow

Google Drive Module: Coming Soon

  • Credential to connect with: Choose your credentials (see how to authenticate here)

  • Resource: choose "File"

  • Operation: download

  • File Path: the path to your file from the root of your Nextcloud

Spreadsheet Module: Field selection is shown in the image below. Name of the Binary property/file is “attachment_0”by default in the Gmail node’s output in n8n. If there are more than 1 attachment then their names will be, attachment_0, attachment_1, attachment_2 and so on.

HTTP Module:

Field Selection: Shown in the images below. For the body of the request, you can either use fields below option or just add JSON. Map the fields coming from the file with the fields for creating a customer (check Customers API documentation for exact field names). For this example, we are only creating customers with name, email, and tags. Use Add Parameter option to add more fields.

File Format:

n8n workflow with Gmail:

Workflow with Nextcloud

How to use it?

  • The list of contacts must be a .csv with the following columns names (only email is mandatory & tags accept several values with comma separator)

    email | tags | first_name | last_name

Ex. file:

Other fields (address..) could be added if needed, ask in the n8n channel :)

  • Put the .csv file in your Nextcloud.

  • Import the following workflow in your N8N account (Workflow > Add worflow. Click menu on the top right > Import from file)

  • Create your Nextcloud credentials following these steps: here

  • In the Nextcloud node, add your credentials and the .csv file path

  • In the HTTP node, change the url domain with your own instance name:

  • In the HTTP node, change the enterprise_id and token with your hub's ID and API key respectiverly.

  • Execute and enjoy!

How it works?

NextCloud Module: This module connects to your Nextcloud server. It will download the .csv.

  • Credential to connect with: Choose your credentials (see how to authenticate here)

  • Resource: choose "File"

  • Operation: download

  • File Path: the path to your file from the root of your Nextcloud

  • Binary property: data (it's the default value)

Spreadsheet Module: reads the .csv file

  • Operation: Read from file

  • Binary Property: data

HTTP Module: makes the POST request to add the list of customers.

The call URL is https://coopcircuits.fr/api/v1/customers The token (the API key) is passed as query parameter.

The enterprise_id is fixed, it's the shop ID. It's passed as a body parameter.

The fields email, first_name, last_name and tags depend on the .csv file. They are inherited from this file and passed as body parameters. As the tag field can get several values separated by comma, the following formula enables to get the list of tags: {{ $json.tags.split(',') }}

Last updated