So here below is the solution.
Step 1
Add your file to your site’s “File List”:
curl --location -s \
-o /dev/shm/upLoadChartOfAccounts.json \
--request POST "https://mysite.me/api/method/upload_file" \
--header 'Authorization: token xxxx:yyyy' \
--header "Accept: application/json" \
--form "file=@/path/to/file/AccountChartOfAccountsTemplate.csv" \
--form "is_private=1";
Notes:
- –location : follow redirects (of Nginx?)
- -s : suppress progress bar
- -o : dump response packet to temporary file
- strings are in double quotes to allow variable expansion in linux shell scripts
- –form “is_private=1” : specify storing under
./sites/mysite/private/files
Step 2
Tell the importer to use that file for “My Company”:
curl --location -s \
-o /dev/shm/installChartOfAccounts.json \
--request POST "https://mysite.me/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa" \
--header 'Authorization: token xxxx:yyyy' \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data-raw "{
\"file_name\": \"/private/files/AccountChartOfAccountsTemplate.csv\",
\"company\": \"My Company\"
}";
Notes:
- strings are in double quotes to allow variable expansion in linux shell scripts, so internal double quotes need to be escaped
"abc \"def\" ghi"
More notes:
- You cannot have two account names with the same name (one of them will be quietly forgotten and the other may appear under the wrong parent)
- You cannot have an account parent that does not exactly match a group account name. (the error message is no help at all if you make that mistake)