Programatically File Based Integrations¶
Lime CRMs file import API lets you programatically create file imports and send the file to a Lime CRM Server. A server host is required to run the import scripts from.
A use case can be integrating Lime CRM with a system that only can export its output as files.
Using the Python Client¶
Set up a Python development environment according to instructions.
Writing import scripts¶
A helper library limeclient
wraps the Lime CRM File APIs and makes it easier to create file based imports.
The documentation for the limeclient
library can be found here.
Info
Limeclient cannot use the admin-user in cloud.
Importing files that need tweaking¶
Lime CRM is very strict about the structure of the file to import. If we want to import documents from other sources that might not adhere to these rules, we need to transform the original data in to something that Lime CRM accepts.
Let's say we have the following file to import:
name;company;email;phone;title
Erica Koss;Jacobi Inc;[email protected];1-978-451-7502x7744;IT
Janna Roob;Beer, Green and Grant;[email protected];317.432.6066;Support
...
We have a single name column that contains both the first and last name. However, the object type we are importing to has a first name and a last name property respectively.
A (naively simple) solution to this is to add a transformation step before we upload our import file where we split the name column into a 'first name' and a 'last name' column:
NORMALIZED_HEADERS = 'first name;last name;company;email;phone;title'
def normalize(infile, outfile):
# Write headers to our normalized file
outfile.write(NORMALIZED_HEADERS + '\r\n')
for content in itertools.islice(infile, 1, None):
name, *row = content.split(';') # Get original columns
first, last = name.split() # Extract first and last names
row = [first, last] + row # Put together the line
outfile.write(';'.join(row) + '\r\n')
outfile.seek(0)
with open('non-normative.txt', 'r', encoding='utf-8') as raw:
with tempfile.TemporaryFile('w+', encoding='utf-8') as fixed:
normalize(raw, fixed)
f = ImportFiles(c).create(filename='non-normative.txt',
content=fixed)
f.delimiter = ';'
f.save()
# ...
Instead of just passing the original file directly to LIME, we create a temporary file that we fill with a normalized version with two columns for storing a name. We then pass this file to LIME instead.
Scheduling imports from a Windows Server¶
File imports can be scheduled to be executed regularly using for example Windows Task Scheduler. Follow these steps:
- Open the Task Scheduler application
- Select Create Basic Task
- Specify name and task trigger (interval)
- Select the Start program action
- Set Program/script to the
pythonw.exe
located in the virtual environment you want to use (i.e.<path to venv>\scripts\pythonw.exe
- Set Add arguments to your Python import script
Tip
Test your script from the command prompt before scheduling it to make sure it works properly.
Info
When running with pythonw.exe
, no console window will be displayed so
you'll not get much feedback as to what's going on. This is probably
what you want in production scenarios where you can use logs to report
errors.
While you\'re setting up the scheduled task you can use python.exe
instead. This displays a console window where you can see print()
statements and even debug your scripts from within the task scheduler.
Note
Unless you point out a specific starting or working folder for the
scheduled task it will be C:\
.