we are very happy with this nice piece of software, it works like a charm.
Now we would like to import our customers from the ERP system via CSV files. The import through the Webui is fine but we are seeking for a method to do this import automatically every day at midnight. Any posibility to do this with a shell script? I´m not so familiar with database imports over command line and I hope this community can help. Thanks a lot in advance.
Hm, Zammad features a REST API, and in theory it should be able to do everything the user interface can do. After all, Zammad’s user interface is completely written in JS and communicates with the backend exactly via this REST API. Unfortunately, the /api/v1/users/import endpoint seems to be undocumented: User — Zammad System Documentation documentation
I’m not sure if this implies that its use is unsupported, or if someone just forget to document it. Until proven otherwise, I’ll just assume the latter
If you want to see how it works, just open your browser dev tools, go the network tab and check “preserve log”, and then run an import. You should see two requests:
The first one is the test run:
POST /api/v1/users/import
Form data: file: (binary) try: true
The response contains the information that is displayed in the “confirm import” button, along with a list of all parsed CSV records.
The second one is the actual import:
POST /api/v1/users/import
Form data: file: (binary) try: false
Practically the same response as from the first request, just try is now of course returned as false.
With this information, it should be pretty easy to automate the import with curl. try=true should enable easy testing, and when your script works reliably, you can probably skip the test run and just use the import request directly.
Ensure that your elasticsearch is up and running and the user are indexed. You then should find them.
You can check that as well by running the following in a rails console ( zammad run rails c):
User.find_by(email: '<EMAIL>')
If you can’t find the user there, check your logfile, something went wrong then.