Product List Export (OFN Product Upload CSV format)

This workflow sends an email to producers with their product list (CSV file). This file can directly be used to update on_hand, price, on_demand values of products and variants on OFN.

Overview

This workflow describes how to use the Products API in n8n to get full list of products/variants and their stock level in the format required by OFN product uploader. This mean, by editing the on_hand, price, on_demand etc. fields, you can use the downloaded CSV to modify product details on OFN using the Product Upload feature.

Description

This workflow gets the product list for an enterprise using products API and then does the product and tax category mapping with the data from OFN database (Postgres) to get all the fields required for CSV upload template.

Reason for doing this is because fields you get from products API are not same as the fields you need for CSV upload template. Ex. Products API only gives tax and product category id (not names), whereas product upload CSV requires tax and product category names (not ids). Similar field disparity is there with fields related to units. Additionally, Shipping Category field is not present in API but it is required in Product Upload CSV. Therefore, Shipping category in this workflow is kept to “Default”. This needs to be manually changed in the downloaded CSV if the shipping categories are different. Note: Instead of using Postgres DB for mapping of tax and product categories, we could have used a function to do that, but in that case we would have to update the function whenever there is a change in tax or product categories.

Prerequisites

To set up this integration you will need:

OFN API Authentication

OFN Database connection (Postgres) for your instance

Gmail account linked in n8n

Workflow

Find the workflow code for download and import here.

How to use/adapt:

  • Download the workflow from the link above.

  • Then go to n8n→Add new workflow.

  • Go to 3 dots menu on the top right corner and select Import from a file.

  • Select the previously downloaded file and you should see something similar to the image below.

    • In case you were not able to download the JSON file mentioned above, then just copy the URL of the page which opens up when you click the workflow link mentioned above (It should be something like this: "https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%xxxxxxxxxxxxxxx"

    • Now instead of importing from a file, select import from a URL.

    • Then paste the URL you copied earlier and add ".json" at the end of the URL. This is important, you won't be able to import the workflow if you don't add ".json" at the end of the URL.

  • After you get the skeleton workflow, you would need to go to few of the modules to update credentials and settings as described below (modules with red triangles).

  • Once you have changed the modules, you can run the workflow by clicking the “Execute workflow” button at the bottom. (Make sure you do a few tests before using this workflow for an actual producers)

  • You can do few test runs by getting product list of a dummy producer and changing it before uploading it back to OFN.

Trigger: Can be manual/scheduled/webhook. No need to change.

Page number and Split Pages modules: These modules are just to split the load of running the products API call (Get bulk products module) for large number of products. No need to be check/edit these modules. This workflow, is limited to get the first 2000 products only. if you want to get more products, then either remove these 2 modules or add more pages in the page number module. At the moment it stops at 10 pages with 200 products in each page.

HTTP Module (Get Bulk Products): By default it will give all the products the user has access to.

  • Change the credentials ("credential for header Auth" field): You would need to add or use an existing OFN credentials of the user you need to run products API for.

  • You need to change the URL to match your instance's URL. Format: https://INSTANCE_URL/api/v0/products/bulk_products

  • To get products of a specific enterprise, use “q[supplier_id_in]” in the query parameters and add their enterprise id as shown below. To get the product list for a hub rather than a specific enterprise, delete this query parameter.

  • Leave per_page and page query parameters as it is or delete them if you are not using page modules at the start of the workflow.

Tax and Product Category Modules:

These modules get a list of all the tax and product categories along with their ids for your instance. Since, every instance can have different product and tax categories, therefore you need to add/use the Postgres credentials for your instance in these modules.

If you don’t see Postgres credential for your instance in the options, then msg in #n8n channel in slack.

Credential names will be in the format of “Open Food Network DB (Instance short form-prod)”

Gmail:

To email the Product list CSV you need to add/use a gmail account in the “Credential to connect with” field.

Along with that, you can modify subject, message, and receivers email. Leave the attachment field as it is.

IMPORTANT: For tests use your email in the "To Email" section. Once you are confident, then you can use producer's email here.

Last updated