Product List Export (OFN Product Upload CSV format)
This workflow exports a producer's product list as a CSV file. This file can then be used to update products and variants on OFN via the Product Import feature.
Last updated
This workflow exports a producer's product list as a CSV file. This file can then be used to update products and variants on OFN via the Product Import feature.
Last updated
Overview
This workflow describes how to use the Products API in n8n to get a full list of products/variants and their stock level in the format required by OFN product uploader. This means by editing the on_hand, price, on_demand etc. fields, you can use the downloaded CSV to modify product details on OFN and then update them using the Product Import feature.
Description
This workflow gets the product list for an enterprise using the Products API and then does the product, shipping and tax category mapping with the data from OFN database (Postgres) to get all the fields required for the CSV upload template.
Not all of the fields required in the Product Import file are present in the API, so these are mapped using Postgres. This updated version of the flow also maps shipping category, which was not included in the first version, meaning that the exported CSV is now a true copy of OFN data. 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
Optional: Gmail or Sendgrid account linked in n8n (not required for a one-off export)
Find V2 of the workflow code for download and import here (older versions found at the bottom of this page):
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: the flow is currently on a manual trigger. This can be swapped to a schedule or a webhook as needed.
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 numbers of products. No need to 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, Product and Shipping 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, you need to add/use the Postgres credentials for your instance in these modules.
If you don’t see Postgres credentials 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)”
This section of the flow highlights products that will cause problems during an import. These include products with a blank space after their name (e.g. 'Oranges_') and products which have variants with different unit types. Both of these characteristics will cause errors in the import, so you can use this section to identify the problem products, amend them in OFN, and re-run the flow.
Alternatively, you can use the 'Matchable Products Export' node to generate an export of only products that won't cause errors.
V1 product export flow: