Import Contacts

Status
Not open for further replies.

CountJuuglar

New Member
Sep 1, 2017
7
1
3
44
Hi, I'm hoping this isnt a dumb question, or was answered elsewhere, but I'm trying to figure out how the contacts import needs to be formatted..... I am familiar with CSV and creating a simple file, but i assume I need X amount of commas to get to X field ..... does anyone have this, or do i need to do a bunch of test imports to figure it out ? Or am I missing something obvious again .... lol
 

Jan Schreiber

New Member
Dec 7, 2017
1
0
1
47
I'd have the same question... I tried to import a contact list, and now the whole FusionPBX contacts directory is full of empty records.
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,500
414
83
Hi, this is something I need to work on, but I just have not had the time so far. The contacts data (depending on what you store) is spread across 11 tables, this is a relational set up so it doesn't easily lend itself to being imported or exported to/from a single flat file like a .CSV.

v_contacts holds the contact entity, name, title, organisation etc. Then if you want to give this entity one or more phone numbers these get added to the v_contact_phones table. If you want to give your contact one or more email addesses these get added to the v_contact_emails table and so on. I'm sure you get the picture.

The key that ties all the records in the various tables together is the contact_uuid. Any import routine/script needs to be able to identify the various elements in the source file (Identity data, phone number data, email data, etc...) Then create a contact record, noting the contact uuid, then create all the child records using the contact uuid as the key.

As the source data will be in lots of different formats from different customers, it's not easy to have a "One size fits all" import, unless someone takes a lot of time to write some sort of import wizard.

When I get around to writing the code for my own imports I will share it on the list. Adrian.
 
Last edited:
  • Like
Reactions: DigitalDaz

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,500
414
83
Hi I have posted this in case it is of help to anyone. I still have not had time to write my own code for contacts import, but this weekend a customer asked me to import 800 contact records so I had to do something. This apples to my Fusion 4.2.3 installation.

I had to modify contact_import.php a little. By default contacts import with no access permissions so I added some code to get the UUID for the users group and add this by default to all imported contacts. I also added the ContactType so this can be supplied in the .CSV. Here is the diff:
Code:
 diff contact_import.php contact_import_orig.php
62,71d61
< // added by AHF - get UUID of users group
<     $sql = "select group_uuid from v_groups where group_name = 'user'";
<     $prep_statement = $db->prepare(check_sql($sql));
<     $prep_statement->execute();
<     $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
<     $contact_vgroup_uuid = $result[0]["group_uuid"];
<     unset ($prep_statement, $sql);
<
<
<
107,108d96
<                             //added by AHF
<                             $contact_type = $data['ContactType'];
141,159d128
<                             $sql .= ")";
<                             $db->exec(check_sql($sql));
<                             unset($sql);
<
<                         //added by AHF add the permission
<                             $contact_group_uuid = uuid();
<                             $sql = "insert into v_contact_groups ";
<                             $sql .= "(";
<                             $sql .= "contact_group_uuid, ";
<                             $sql .= "domain_uuid, ";
<                             $sql .= "contact_uuid, ";
<                             $sql .= "group_uuid ";
<                             $sql .= ")";
<                             $sql .= "values ";
<                             $sql .= "(";
<                             $sql .= "'$contact_group_uuid', ";
<                             $sql .= "'".$_SESSION['domain_uuid']."', ";
<                             $sql .= "'$contact_uuid', ";
<                             $sql .= "'$contact_vgroup_uuid' ";
It still doesn't import URLs, Email addresses etc. but it does do contacts, all the addresses and all the phone number types.

The CSV header is important, it determines what will be imported and obviously you have to match it to the .CSV data you have. Here are the list of headings it will now import:
"ContactType","Title","FirstName","LastName","Company","EmailAddress","Notes","Web Page",
"BusinessStreet","BusinessCity","BusinessState","BusinessPostalCode","BusinessCountry","HomeStreet",
"HomeCity","HomeState","HomePostalCode","HomeCountry","OtherStreet","OtherCity","OtherState",
"OtherPostalCode","OtherCountry","BusinessFax","BusinessPhone","BusinessPhone2","CompanyMainPhone",
"HomeFax","HomePhone","HomePhone2","MobilePhone","OtherFax","OtherPhone","Pager","PrimaryPhone"

So a very simple .CSV file to import may look something like this:
"ContactType","Company","CompanyMainPhone"
"supplier","A B C Ltd","01234 56789"
"customer","Joe Bloggs Ltd","0987 654321"

I hope this is helpful. Adrian.
 

roger_roger

Member
Oct 12, 2016
198
19
18
70
On the new 4.4 Fusionpbx, just create your CSV in any way you wish. When you import it, fusion presents a screen that allows you to map each CSV field to a specific contact field. You don't need a header record as the first record. Check it out.
 

Claudio

New Member
Jan 3, 2018
18
0
1
41
So I started messing with this today and yes the new import allows you to map values based on your import template. The problem still remains that if you cannot assign "User" and "Group" in the csv and map it during import this is useless for bulk importing. The contacts will never be visible without these options. Am I missing some variable in my template or is everyone seeing the same issue ?


Claudio.
 

IvanoDesco

New Member
Dec 13, 2018
1
0
1
45
Does anybody know how to import contacts with multiple numbers?
I can get it to work with only one number but not with more.
 

gflow

Active Member
Aug 25, 2019
267
31
28
@roger_roger Thankyou for the update. I hoped the import would be fixed in a later version. I have had no exposure to 4.4 yet!

Adrian.
Hi Adrian, Did you ever find a fix for importing contacts in FusionPBX 4.4 so that you can add user and/or group with the contacts imports and set the phone_type_voice to true?
 
Status
Not open for further replies.