CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Is it possible to import tag sets?
Pages: [1]

Author Topic: Is it possible to import tag sets?  (Read 1213 times)

lynx

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Joomla 2
  • MySQL version: 5.5.40
  • PHP version: 5.3.29
Is it possible to import tag sets?
January 16, 2015, 07:36:20 am
If so, how? How does the data need to be prepared? I couldn't find anything through searching. Even importing (assigning) tags seemed to require hacks.

I'd like to add a paragraph about this to the book, so solid info is needed.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Is it possible to import tag sets?
January 16, 2015, 07:42:15 am
You can't import tags through the normal interface.  You can use the API to do it though.  That means either writing a script, or using the CSV API import tools.  There's a command-line tool that ships with CiviCRM and a GUI that ships as an extension:
https://civicrm.org/blogs/xavier/api_batch_tools
https://civicrm.org/extensions/api-csv-import-gui

In either case, you can do an export to see the format the import needs to be in.
I'm not sure it's a great candidate for the book though.  Unfortunately, this isn't really a method aimed at end users at this time.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

lynx

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Joomla 2
  • MySQL version: 5.5.40
  • PHP version: 5.3.29
Re: Is it possible to import tag sets?
January 16, 2015, 08:06:44 am
That GUI is part of core now, unless it is identical to the normal import. Hard to say since it isn't latest code. And if it wasn't clear enough, the question is not about importing tags alone, but importing contacts and assigning individual tags (in extra data col(s)) in the process.

It is known exporting has documented limitations / design decisions taken, so it's not that helpful for figuring out import requirements.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Is it possible to import tag sets?
January 16, 2015, 08:35:25 am
Hi Lynx,

I'm not sure what you mean by, "That GUI is part of core now, unless it is identical to the normal import."  Are we referring to the API GUI CSV import extension?  That's definitely not part of core, but I may be misunderstanding what you're saying.

I agree that export limitations sometimes mean that it's not helpful for figuring out import requirements, but in the case of API-based import/export to CSV using the tools mentioned, it's actually a very good way to determine data formats.

To reanswer your question in light of new info though:  There isn't a way to assign tags using the core "Import Contacts" based on their presence in additional data columns.  You can assign a (single) tag to all imported contacts. 

I'm happy to share my ETL scripts with you that I use for doing exactly what you're asking (I'll put them on Github).   However, they require Pentaho Kettle, which has a learning curve that makes it inappropriate as a solution for end users.  It involves normalizing the tags field, then doing SQL lookups (or API lookups, if I don't have SQL access) based on civicrm_contact.external_identifier to get the contact_id, then a similar lookup against the civicrm_tag.name field to get the tag_id, and outputting to CSV.  I then take my CSV of contact_id and tag_id pairs, and use the CLI import:
/path/to/civicrm/bin/csv -e EntityTag --file=/path/to/tag_import.csv.

I wish I had a better answer for you - it's certainly something Civi could do better!  Short of coding a solution similar to mine though, I can offer two other solutions:
* Create temporary custom fields, import your data to those fields, then do searches on that data and adding the contacts found to a tag.  That works for 10-20 tags - not so much for the 500+ tags you might be dealing with if, e.g., you're coming from Salsa.
* Filter your CSV by a tag, save the results to a separate CSV (you only need to save enough info to match the contact - e.g. the External Identifier).  Do this for each tag.  Import each list, specifying the tag for each import.

Again - I wish I had a better answer, but I hope this is helpful!
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Is it possible to import tag sets?
January 16, 2015, 11:59:09 am
Quote from: JonGold on January 16, 2015, 08:35:25 am
I'm happy to share my ETL scripts with you that I use for doing exactly what you're asking (I'll put them on Github).   However, they require Pentaho Kettle, which has a learning curve that makes it inappropriate as a solution for end users.  It involves normalizing the tags field, then doing SQL lookups (or API lookups, if I don't have SQL access) based on civicrm_contact.external_identifier to get the contact_id,


Tangential: it's now possible to update a contact by matching it directly by the external identifier, it might save you the lookup external id->internal id

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Is it possible to import tag sets?
January 16, 2015, 12:02:47 pm
Xavier - good to know!  I assume I do this via the options when using CSV import?  Now if only I could do API chaining from the CSV import...

Also - I guess I'd considered using the "match=external_identifier" in the past, but decided that the performance couldn't possibly be as good as using Kettle to do a SQL lookup against a cached table.  I can look up over 100,000 IDs per second that way.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

lynx

  • I’m new here
  • *
  • Posts: 20
  • Karma: 0
  • CiviCRM version: 4.5
  • CMS version: Joomla 2
  • MySQL version: 5.5.40
  • PHP version: 5.3.29
Re: Is it possible to import tag sets?
January 18, 2015, 05:47:47 am
Ok, thanks guys. I'm not sure what I'll do for our setup yet, as I can't even set tag sets manually (something for a different thread), but the docs now have a short blurb about available options.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Is it possible to import tag sets?

This forum was archived on 2017-11-26.