Guides

Import a CSV into ERPNext, and update the items that already exist

Turn another system's item list into ERPNext items: new ones are created, changed ones updated, unchanged ones left alone, and refused rows are explained.

A 35 second recording of the finished workflow. The Map fields sheet opens on the standard_rate row, filled with ListPrice and turned into a number. Run now asks for a CSV, and the next day's item list is chosen. The run finishes with Updated 2, Created 1, Already sent, unchanged 9 and Skipped 1. The skipped row is RV-8001 with ERPNext's message: Could not find Item Group: Fasteners.

The second import, from Run now to the refused row.

The example is made up: Corbett Industrial Supply is a distributor moving its item list from an older system into ERPNext. Everything in the screenshots runs on a test machine, so nothing here touches a real system.

One row of the old system's item list
ItemCode,Description,Group,Unit,ListPrice
HX-1001,Hex bolt M8 x 40 zinc,Products,Nos,0.45
The same item, as ERPNext receives it
PUT /api/resource/Item/HX-1001
{
  "item_code": "HX-1001",
  "item_name": "Hex bolt M8 x 40 zinc",
  "item_group": "Products",
  "stock_uom": "Nos",
  "standard_rate": 0.45
}
Run details of Item list into ERPNext, the second import. The result is 1 skipped, with 3 records. The line under it says Updated 2, Created 1, Already sent, unchanged 9, Skipped 1. The Create record in ERPNext step says the same. Skipped rows lists line 11, RV-8001, status 417, Could not find Item Group: Fasteners, with a Source data tag. Below it, Already sent, unchanged lists 9 items. (opens the full size image in a new tab)Run details of Item list into ERPNext, the second import. The result is 1 skipped, with 3 records. The line under it says Updated 2, Created 1, Already sent, unchanged 9, Skipped 1. The Create record in ERPNext step says the same. Skipped rows lists line 11, RV-8001, status 417, Could not find Item Group: Fasteners, with a Source data tag. Below it, Already sent, unchanged lists 9 items. (opens the full size image in a new tab)
The second import: 2 updated, 1 created, 9 left alone.

What you end up with

  • You run it with the day's file, or it picks the file up from a folder each night.
  • New items are created in ERPNext, changed ones are updated, and unchanged ones are not sent at all.
  • Each row ERPNext refuses is listed with its line, its item code and ERPNext's own message.

Needs the Starter, Pro or Business plan. You also need an ERPNext site on version 16, someone who can sign in to it and create and change items, and a Ladeworks account (Start free is below).

Why not ERPNext's own Data Import?

For a one-off import, use it: ERPNext's Data Import tool takes a CSV or a spreadsheet and is built for exactly that. This workflow is for the import you do again and again, from a file another system keeps writing. It remembers what it sent, so each new file only creates and updates what changed, and it tells you why a row did not go in.

How it works, in four steps

1. Connect ERPNext

ERPNext is a built-in integration, so there is no key or secret to make. On the Integrations page choose Add an integration, then Connect to ERPNext, type your site address, such as acme.frappe.cloud, sign in to ERPNext and approve access. Connecting has the details.

ERPNext's ready-made actions find, add and read records, but none of them updates an item that already exists, so this workflow uses ERPNext's other endpoints, the All endpoints list on the connection: Create a record (POST /api/resource/:doctype) creates a record and Update a record (PUT /api/resource/:doctype/:name) updates one. They work for every record type your site has, and so does the rest of ERPNext's API.

2. Read the item list

On the Workflows page choose New workflow, then Blank, then Set up manually. Choose Only when someone clicks Run, then A CSV you upload as the source. For the destination choose ERPNext, then Use another endpoint and Create a record (POST /api/resource/:doctype). Name the workflow, and choose Create workflow. (You can also describe the job under What should this workflow do? and let Ladeworks draft the steps; check each one against this guide.) A workflow that reads an upload runs when someone chooses Run now and picks the file. In the first step, Choose a sample CSV reads the columns of one item list, so the next step can list them. To pick the file up from a folder each night instead, see the folder variation.

3. Map the columns to ERPNext's Item fields

ERPNext's generic endpoint does not list an item's fields, so the Map fields sheet has a row for each column of the file, named after it, and you type the ERPNext field name into each row's name box.

Old systemERPNext fieldWhat happens to it
ItemCodeitem_codeRenamed. It is also the item's name in ERPNext.
Descriptionitem_nameRenamed
Groupitem_groupRenamed. It must be an Item Group ERPNext has.
Unitstock_uomRenamed. It must be a unit ERPNext has, such as Nos.
ListPricestandard_rateChange the value, then Turn into a number
NothingdoctypeFilled with a fixed value, Item. Choose + Add a field, name it doctype, set Fill with to A fixed value and type the value.

The doctype fills the :doctype in ERPNext's address, so every row goes to /api/resource/Item. Under Fields not used, choose Leave out. Choose Update to keep the sheet.

The Map fields sheet for ERPNext. doctype is required and filled with the fixed value Item. Below, five rows name ERPNext fields (item_code, item_name, item_group, stock_uom, standard_rate), each filled from a column of the file, with a gray line that ERPNext does not list the field and it is still sent. The standard_rate row is open: Fill with is A field, ListPrice, and Change the value is Turn into a number. Fields not used is set to Leave out. (opens the full size image in a new tab)The Map fields sheet for ERPNext. doctype is required and filled with the fixed value Item. Below, five rows name ERPNext fields (item_code, item_name, item_group, stock_uom, standard_rate), each filled from a column of the file, with a gray line that ERPNext does not list the field and it is still sent. The standard_rate row is open: Fill with is A field, ListPrice, and Change the value is Turn into a number. Fields not used is set to Leave out. (opens the full size image in a new tab)
ListPrice becomes standard_rate, as a number.

4. Create it, or update it if it is there

In the last step, open More settings and turn on Update it if it already exists and set Match on this field to item_code. Turn on Update it with the key directly, because an ERPNext item's address is its item code, and choose Update a record (PUT /api/resource/:doctype/:name) under Update it with. Ladeworks sends the update first and creates the item when ERPNext answers that it does not exist.

Don't send records that were already sent is on already, and tells records apart by item_code. An item whose row has not changed since it was last sent is left out, and it is not a record.

The settings of Create record in ERPNext, with More settings open. The integration is ERPNext and the endpoint is Create a record, POST /api/resource/:doctype. Don't send records that were already sent is on, telling records apart by item_code. Update it if it already exists is on, matching on item_code, with Update it with the key directly on and Update a record, PUT /api/resource/:doctype/:name. The last line reads Update, or create on 404: PUT /api/resource/{doctype}/{item_code}. (opens the full size image in a new tab)The settings of Create record in ERPNext, with More settings open. The integration is ERPNext and the endpoint is Create a record, POST /api/resource/:doctype. Don't send records that were already sent is on, telling records apart by item_code. Update it if it already exists is on, matching on item_code, with Update it with the key directly on and Update a record, PUT /api/resource/:doctype/:name. The last line reads Update, or create on 404: PUT /api/resource/{doctype}/{item_code}. (opens the full size image in a new tab)
Create or update, by item code.

Choose Save. To try it, choose Run now, pick the file and choose Run with this file.

The Steps tab of Item list into ERPNext, Active. The trigger card says it runs only when someone clicks Run. Below are Read the uploaded CSV, Map fields (Fills 6 ERPNext fields from the file), and Create record in ERPNext, which creates records or updates them when item_code already exists and leaves out records already sent. (opens the full size image in a new tab)The Steps tab of Item list into ERPNext, Active. The trigger card says it runs only when someone clicks Run. Below are Read the uploaded CSV, Map fields (Fills 6 ERPNext fields from the file), and Create record in ERPNext, which creates records or updates them when item_code already exists and leaves out records already sent. (opens the full size image in a new tab)
The finished workflow.

When a row is wrong

The first item list had 12 rows. ERPNext created 11 items and refused one: a box of rivets in the group Fasteners, which does not exist in ERPNext. The run does not stop for it. It lists the row with its line, its item code, ERPNext's status 417 and ERPNext's own words, and tags it Source data: the value went out exactly as it is in the file.

Run details of the first import: 1 skipped, 11 records, Created 11, Skipped 1. Skipped rows shows line 11, RV-8001, 417, Could not find Item Group: Fasteners, with the Source data tag and the buttons View request and Retry row, and Retry 1 skipped row above it. (opens the full size image in a new tab)Run details of the first import: 1 skipped, 11 records, Created 11, Skipped 1. Skipped rows shows line 11, RV-8001, 417, Could not find Item Group: Fasteners, with the Source data tag and the buttons View request and Retry row, and Retry 1 skipped row above it. (opens the full size image in a new tab)
The first import: 11 created, 1 refused, with the reason.

Fix it on either side. If you add the Item Group in ERPNext, choose Retry row: it sends the row again as it was. If you change the group in the old system, the next file carries it, because a refused row was never sent and so is tried again. The next day's file had 13 rows, with two new prices and one new item. The run updated 2, created 1 and left the other 9 out: 3 records, against 11 the day before.

Before you go live

  • Test on a copy of ERPNext first. Test sends only the first row of the file, and it really creates that item. It asks first (Send a test?).
  • Groups and units must exist. Create the Item Groups and units your file uses, or the rows are refused.
  • Connect as someone with only the access the job needs. Ladeworks can do what the person who approves can do in ERPNext, and nothing more. Someone who can create and change items is enough.
  • The first run sends everything. Items already in ERPNext are updated with the file's values.
  • Leaving a column out leaves the field alone. An update changes only the fields you send.

Start free

Connect your own systems and build this workflow yourself. Nothing reaches your systems until you run it or switch it on.

Start free

Setup details

You do not need these to follow the story. Open one when you reach that step.

Connect ERPNext to Ladeworks

On the Integrations page choose Add an integration, then Connect to ERPNext. Ladeworks asks for Your ERPNext site address: the address you open ERPNext at, without https://, such as acme.frappe.cloud. You go to your own site, sign in as yourself and approve access, and you come back to Ladeworks connected. ERPNext version 16 or later is needed.

Triggers that start the moment something changes need the person who connects to be a System Manager; everyone else gets changes read on a timer. This workflow starts when someone clicks Run, so it does not matter here. ERPNext in Built-in integrations has every step, including Reconnect and Disconnect.

Frappe's generic endpoints

Every ERPNext record type, called a doctype, uses the same five endpoints. :doctype is the type, such as Item or Customer, and :name is the record's name, which for an item is its item code. The connection's All endpoints list names them List records of any type, Create a record, Read one record, Update a record and Delete a record, and has more for common record types.

GET    /api/resource/:doctype          list records
POST   /api/resource/:doctype          create one
GET    /api/resource/:doctype/:name    read one
PUT    /api/resource/:doctype/:name    change the fields sent
DELETE /api/resource/:doctype/:name    delete one

ERPNext answers with the record inside data, such as {"data": {"name": "HX-1001", ...}}, and a list as {"data": [...]}. Ladeworks finds the records inside data by itself. A refusal comes back with a status such as 417 and a message, which Ladeworks reads out of Frappe's answer and shows on the row. A missing item answers 404, which is what Update it with the key directly uses to know it should create the item.

The same steps work for customers, suppliers or prices: change the fixed doctype and the fields.

Pick up the file from a folder each night

If the old system writes its item list to a folder on an SFTP, FTPS or FTP server, Ladeworks can pick it up. Connect the server as a file server with a Pick up files folder, then choose that folder as the source on New workflow, and When a file lands as the trigger. Needs the Starter, Pro or Business plan. Set For files named to the file's pattern, such as items_*.csv, and After the run to move the file to a processed folder. Each file that lands starts a run, and the rest of the workflow stays the same.

Connect a file server and When a file lands have the details.

Going the other way, from ERPNext to a file? See Export ERPNext items to a CSV every night. More in the docs: Update it if it already exists, Map fields and Reading a run.

More guides: all guides. How each step works: the docs.