Lead Import
Precious Leads provide users the ability to import leads. This is useful when the user wants to migrate from another CRM or simply wants to add to Precious Leads a list of leads he already has.
In order to be ablet to import leads, you must have Redis and Celery running, as specified in the Backend Configuration section.
Permissions
When it comes to importing leads, the permissions are as follows:
1. All users except Lead Users have permission to import leads.
2. Import is only available in paid plans.
That’s it.
Flow
The flow for importing leads is as follows:
1) Front end makes a POST to the pre-signed URL endpoint with filename in the body. Backend returns file_url and file_path. 2) Front end uploads the file by making a PUT to the file_url. 3) Front end makes a POST to the import endpoint, including the file_path in the body, along with other required parameters.
The endpoint for requesting a pre-signed URL is:
/get-presigned-url/
The endpoint for importing leads is:
/leads/import/
This will return a response in the form of:
{
"detail": "CSV file submitted successfully.",
"task_id": "900fa962-a4b5-4375-aae0-3b5e7b90feb6"
}
In order to check the status of the import, it is recommended that you use a GET request to the same endpoint using the task_id, as follows:
/leads/import/?task_id=900fa962-a4b5-4375-aae0-3b5e7b90feb6
This will return a response in the form of:
{
"state": "SUCCESS",
"result": {
"progress": "Import finished.",
"total_leads": 6837,
"imported_leads": 6835,
"leads_with_errors": 2,
"errors": [
{
"item": {
"full_name": "Saredam C Hernandez",
"phone": "1541297527",
"email": "saredam"
},
"errors": {
"email": [
"Enter a valid email address."
]
}
},
{
"item": {
"full_name": "Miranda Miranda",
"phone": "5617146533",
"email": "@yahoo.com"
},
"errors": {
"email": [
"Enter a valid email address."
]
}
}
]
}
}
Import Task Model
In order to provide more functionality, the backend also updates the database with information about all imports.
Some benefits of doing this are:
1. It allows us to have an “Import Dashboard” where we can show users a history of all their imports.
2. It gives the user the ability to check for errors and fix them (or discard those leads if he chooses to). While this could be done using the check import status endpoint, I believe the Celery task_id is short lived and therefore not available after several days.
3. It associates each lead with their import task, allowing us to query all leads of a particular import or implement features such as “Undo Import”.
The endpoints for this model are specified in Bruno.
When fetching this model, you will get a response such as:
{
"id": 1,
"category_id": 1,
"submitted_by_user_id": 2,
"celery_task_id": "900fa962-a4b5-4375-aae0-3b5e7b90feb6",
"state": "SUCCESS",
"progress": "Import finished.",
"total_leads": 6837,
"imported_leads": 6837,
"leads_with_errors": 0,
"errors": []
}
This information can be used for an import dashboard or a results modal.
Fetching a Category and showing a modal
It is important to notify users about their imports.
This is accomplished while fetching the category.
When you GET a category, this will return a response in the form of:
{
...
"unchecked_import_tasks": [
{
"import_id": 3,
"submitted_by_user": "Yuan Hao Chiang",
"state": "SUCCESS",
"progress": "Import finished.",
"imported_leads": 6833,
"leads_with_errors": 4
}
],
...
}
The unchecked_import_tasks will list all the imports that the user has not acknowledged yet.
If the state is PENDING or STARTED:
We could show a message inside the category saying someting like:
| “Lead import is currently in progress, please come back later”. | | —— |
There’s just one problem with this.
If the lead import is stuck for some reason, the lead dashboard would become unusable.
Another option would be allow the user to continue using the lead dashboard while the import is taking place, but I don’t know how the front end would behave.
If the state is SUCCESS:
Then we have two options.
If the import has no errors, we can show a message saying:
| “The lead import submitted by Yuan Hao has finished successfully.” | Ok got it! | Review results | | ——- |:—-:| —:|
Clicking on “Ok got it!” will update the Import Task model with user_checked=true.
Clicking on “Review results” will open a small modal with the import stats. In that modal we could show a button such as “Ok” that once clicked it will update the Import Task model with user_checked=true.
We could also simply get rid of “Review results” and have the user click on “Ok got it!” and that’s it.
If the import has errors, we can show a message saying:
| “The lead import submitted by Yuan Hao finished with some errors.” | Fix errors | | ——- |:—-:|
Clicking on “Fix errors” will open a page or modal allowing the user to fix those leads.
ABOUT FIXING ERRORS: Fixing import errors might turn out to be complicated. What if it’s an import of 10k leads and there are 2478 leads with errors (incorrect email formats)? Or even worse, what if it’s an import of 100k leads and ALL of them have errors?
Maybe we should simply notify the user of the errors and generate a CSV file with those leads that contain errors, so that the user can fix the CSV file an submit it again for import.
Fetching a Lead
When fetching a lead that was added by an import, you will get a response that contains the import associated with it:
{
...
import_task_id: 1
...
}
If the lead was not imported, the import_task_id will be null.
This import_task_id could be used in the future to implement “filtering leads by import” or “undoing an import”.
Important considerations
When importing leads, we should be mindful of:
- Allowing users to assign or distribute those leads according to their criteria.
- Allowing users to specify a status for the incoming leads.
- Validating and mapping the name of the fields.
- Setting a maximum file size limit.