# Command Line Import

**URL:** <https://forum.mautic.org/t/command-line-import/11852>\
**Category:** Product Support\
**Created:** [December 2, 2019, 2:08pm UTC](https://forum.mautic.org/t/command-line-import/11852 "2019-12-02T14:08:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 2, 2019, 2:08pm UTC](https://forum.mautic.org/t/command-line-import/11852/1 "2019-12-02T14:08:18Z")

</div>

**Your software**  
My Mautic version is: 2.15.x  
My PHP version is: PHP Version 7.2.24-0ubuntu0.18.04.1

**Your problem**  
My problem is:  
I would like to import a list of DONOTCONTACT into my Mautic using a cronjob.  
My file would contain two columns: “email”, “DONOTCONTACT”

I am already using **[mautic-custom-import-bundle](https://github.com/mtcextendee/mautic-custom-import-bundle)** to import my system info into Mautic, so cannot use this as well.

These errors are showing in the log:

Steps I have tried to fix the problem:

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 9, 2019, 9:40am UTC](https://forum.mautic.org/t/command-line-import/11852/2 "2019-12-09T09:40:47Z")

</div>

bumping this up… would appreciate any direction here.

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [December 9, 2019, 10:45am UTC](https://forum.mautic.org/t/command-line-import/11852/3 "2019-12-09T10:45:10Z")

</div>

It is unclear what you want to achieve or what the issue is.  
You can just import the list to a segment…

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 9, 2019, 11:15am UTC](https://forum.mautic.org/t/command-line-import/11852/4 "2019-12-09T11:15:13Z")

</div>

Hey Yosu,

Thanks for the reply. Let me try and explain myself a bit better.

I am running multiple instances of Mautic and would like to centralise my DONOTCONTACT list automatically.

So what I have done is write a small bash script triggered by a cronjob, so each day the script connects to Mautic mysql, extracts the DONOTCONTACT from the table lead\_donotcontact and saves this into a file. I then run a sftp cronjob to transfer this from my different Mautic instances to a central instance, and on this central instance (example Mautic1) I want to automatically import these contacts and flag them as DONOTCONTACT.

Now as I have mentioned there is a plugin that does this for you, however I am already using this plugin to automatically import data from my program platform into Mautic, and the limitations on this plugin is you can only have one type of mapping.

So my question is - is there a way to automatically import a file (csv) from the command line into Mautic, do I have to setup mapping ?

Does this make more sense to you ?

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [December 9, 2019, 1:25pm UTC](https://forum.mautic.org/t/command-line-import/11852/5 "2019-12-09T13:25:58Z")

</div>

Yes there is a cronjob for importing contacts, you just need to add the csv file on the right folder…

mautic:import

Here’s the full list of cron jobs and what they do:

> **[Mautic cron jobs: Which ones to use? | mauteam.org](https://mauteam.org/mautic/mautic-admins/mautic-cron-jobs-which-ones-to-use/)**
>
> There are many Mautic cron jobs you can use in your Mautic installation, but Mautic can get resource hungry over time, so you don’t really want to run them all, in fact, that would be a great mistake…

---

<div class="post-metadata">

**Author:** ![kuzmany](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kuzmany/32/390_2.png) [@kuzmany](https://forum.mautic.org/u/kuzmany)\
**Post date:** [December 9, 2019, 2:02pm UTC](https://forum.mautic.org/t/command-line-import/11852/6 "2019-12-09T14:02:53Z")

</div>

Try column `doNotEmail` for do Not Contact flag

[https://www.mautic.org/docs/en/contacts/import.html](https://www.mautic.org/docs/en/contacts/import.html)

Then you should see field with same name for DNC processign

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/f/f53883928ae2ab073f4294bc96f55763bb92811d.png)

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 18, 2019, 9:46am UTC](https://forum.mautic.org/t/command-line-import/11852/7 "2019-12-18T09:46:14Z")

</div>

Hi Guys,

Thanks for the help. However I am still unable to wrap my head around this. I ran a test and created a file with the following:

Email,doNotEmail  
[test1@gmail.com](mailto:test1@gmail.com),TRUE

I already had a contact in Mautic with [test1@gmail.com](mailto:test1@gmail.com)

I then put this file in /var/www/mautic/app/cache/import/

and then ran the following two cronjob:  
sudo php /var/www/mautic/app/console mautic:import:directory  
sudo php /var/www/mautic/app/console mautic:import

The result was 1 inserted and 1 ignored, and then it added a records in contacts  
Name = [test1@gmail.com](mailto:test1@gmail.com) True and nothing else.

It did not merge the contacts and add the DNC flag to it.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 23, 2019, 12:54pm UTC](https://forum.mautic.org/t/command-line-import/11852/8 "2019-12-23T12:54:03Z")

</div>

bumping this up again, maybe one of the previous contributors can shed some light on this matter. I am sure the user case could be good for others.

---

<div class="post-metadata">

**Author:** ![kuzmany](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kuzmany/32/390_2.png) [@kuzmany](https://forum.mautic.org/u/kuzmany)\
**Post date:** [December 25, 2019, 9:44pm UTC](https://forum.mautic.org/t/command-line-import/11852/9 "2019-12-25T21:44:48Z")

</div>

doNotEmail should be 1 or 0  
not TRUE

---

<div class="post-metadata">

**Author:** ![MxyzptlkFishStix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mxyzptlkfishstix/32/1132_2.png) [@MxyzptlkFishStix](https://forum.mautic.org/u/MxyzptlkFishStix)\
**Post date:** [December 26, 2019, 3:54am UTC](https://forum.mautic.org/t/command-line-import/11852/10 "2019-12-26T03:54:17Z")

</div>

It works with TRUE.

Email needs to be lowercase though.

Example:  
`email,doNotEmail`  
`test1@gmail.com,TRUE`

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 26, 2019, 12:18pm UTC](https://forum.mautic.org/t/command-line-import/11852/11 "2019-12-26T12:18:18Z")

</div>

Hi

I am still getting the same results, and going crazy pulling my hair out as to what the problem is.

I have done it with both TRUE and 0/1 and each import simple pulls in my line from csv into name. It does not update the specific record.

Can you confirm that you have done this via command line using app commands

---

<div class="post-metadata">

**Author:** ![MxyzptlkFishStix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mxyzptlkfishstix/32/1132_2.png) [@MxyzptlkFishStix](https://forum.mautic.org/u/MxyzptlkFishStix)\
**Post date:** [December 26, 2019, 7:38pm UTC](https://forum.mautic.org/t/command-line-import/11852/12 "2019-12-26T19:38:12Z")

</div>

It worked for me.

I downloaded the 1.0.4 release, extracted it, renamed it and placed it in the `/apps/plugins/` directory. I deleted the cache, configured the CustomImport features section and enabled the plugin.

I put a test.csv file with a dummy contact in `/apps/cache/imports/`.

I ran `php7.2 console mautic:import:directory` and `php7.2 console mautic:import`.

This is the result.

 ![](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/3/3104647a8d1831ae90da3bf0ce4c0fe2f93bd002.jpeg)

The new contact was added successfully with DNC set.

Addendum:

I even added a new csv with the contact details for DNC set to 0, false and blank. In each instance, it removed the DNC.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 27, 2019, 11:22am UTC](https://forum.mautic.org/t/command-line-import/11852/13 "2019-12-27T11:22:12Z")

</div>

Hi MxyzptlkFishStix,

Thanks for the reply however I think you might have missed my initial post. I already use Mautic-custom-import-bundle:  
" I am already using **[mautic-custom-import-bundle](https://github.com/mtcextendee/mautic-custom-import-bundle)** to import my system info into Mautic, so cannot use this as well."

This works great and I use it to bring in platform information into Mautic.

I am looking for an alternative method to import WITHOUT using the custom-bundle, as the limitation of custom bundle is that you can only use one template file.

---

<div class="post-metadata">

**Author:** ![MxyzptlkFishStix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mxyzptlkfishstix/32/1132_2.png) [@MxyzptlkFishStix](https://forum.mautic.org/u/MxyzptlkFishStix)\
**Post date:** [December 27, 2019, 1:02pm UTC](https://forum.mautic.org/t/command-line-import/11852/14 "2019-12-27T13:02:31Z")

</div>

I used an instance of Mautic without the plugin and it added DNC and removed it. I tested it with true/1 and false/0/(blank).

 ![](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/0/03deabaa5b6c362d5f0a51f162f3dc2881b907be.jpeg)

 ![](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/6/6732eeb62a7831216ec435e6415b2a0ea9373068.jpeg)

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [December 31, 2019, 1:28pm UTC](https://forum.mautic.org/t/command-line-import/11852/15 "2019-12-31T13:28:16Z")

</div>

Thanks for the help. I still am unable to get it to work ☹  
I have done exactly what you are explaining and still on the update all I am getting is under name the email and (1/0/TRUE). It is not updating the specific record, rather just adding a new one.

---

<div class="post-metadata">

**Author:** ![MxyzptlkFishStix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mxyzptlkfishstix/32/1132_2.png) [@MxyzptlkFishStix](https://forum.mautic.org/u/MxyzptlkFishStix)\
**Post date:** [December 31, 2019, 7:10pm UTC](https://forum.mautic.org/t/command-line-import/11852/16 "2019-12-31T19:10:48Z")

</div>

Is Email, under Custom Fields, set to Publicly Updatable?

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [January 2, 2020, 6:14pm UTC](https://forum.mautic.org/t/command-line-import/11852/17 "2020-01-02T18:14:34Z")

</div>

Hey,

I got so excited when I saw your last post as it was not set to Publicly Updateable. So I went ahead and did what you suggested:

 ![Screen Shot 2020-01-02 at 19.56.01](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/a/a828b20e8e422f8e05a803d41dd549a8f18fb64f.png)

Then I went and created a record to test in mautic:

 ![Screen Shot 2020-01-02 at 19.56.48](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/6/6234cef7c9229b7f165b38dcdf7eb4f7d99c95da.png)

Next I created the file to import:

 ![Screen Shot 2020-01-02 at 19.58.00](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/7/7e6ba107fd70a233a332fb8850d78b60e184c863.png)

Then went ahead and ran the imports:

 ![Screen Shot 2020-01-02 at 19.59.47](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/7/72f68a63eabb00427f8d962ee971ce50ae0ee5d0.png)

This is the output I got in Mautic:

 ![Screen Shot 2020-01-02 at 20.02.27](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/6/6a689fe7b3c5e0b283c7f297b87e296c61fcf88c.png)

So went ahead and made a file with doNotEmail blank and this was the result:

 ![Screen Shot 2020-01-02 at 20.11.10](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/8/858620f9a19cb256ea9b797af712a206fe8a0b2b.png)

Feeling a little dumb at the moment as I am sure I am missing something so small.

I had a look at your screenshot and wonder what the results were in Mautic as the output of the results says: “2 lines were processed, 1 items created, 0 items updated, 1 items ignored in 0.142 s”. which makes me wonder if you get the same results I am seeing.  
The actual import command works, but even on yours it created a NEW record and did not update any existing records.

Looking forward to hearing back on this issue

---

<div class="post-metadata">

**Author:** ![MxyzptlkFishStix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mxyzptlkfishstix/32/1132_2.png) [@MxyzptlkFishStix](https://forum.mautic.org/u/MxyzptlkFishStix)\
**Post date:** [January 2, 2020, 11:41pm UTC](https://forum.mautic.org/t/command-line-import/11852/18 "2020-01-02T23:41:07Z")

</div>

Publicbly updatable should be set to the default of No. Sorry that I wasn’t clear on that.

Contact added from import with DNC enabled/disabled via import.

Contact added in Mautic first and DNC enabled/disabled via import.

---

<div class="post-metadata">

**Author:** ![MxyzptlkFishStix](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mxyzptlkfishstix/32/1132_2.png) [@MxyzptlkFishStix](https://forum.mautic.org/u/MxyzptlkFishStix)\
**Post date:** [January 2, 2020, 11:56pm UTC](https://forum.mautic.org/t/command-line-import/11852/19 "2020-01-02T23:56:30Z")

</div>

Is that an empty line at the top of your file?

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [January 3, 2020, 3:10pm UTC](https://forum.mautic.org/t/command-line-import/11852/20 "2020-01-03T15:10:13Z")

</div>

Hi,

No there is not another line in the file.

[Next page](https://forum.mautic.org/t/command-line-import/11852.md?page=2)
