Programmatically import a feed I can successfully import remote content using the Feeds module by manually clicking on the Import button. I need to execute the import process from code, either from a module or executing PHP code from the Rules module.

I have tried the following code in a custom module.

function imports_cron_cron(){
  drupal_set_message('Import-CRON responding to cron execution! ...');
  $importer_id = 'publications_import';
  $url = "http://xml/url";
  $feeds_source = feeds_source($importer_id);
  $feeds_config = $feeds_source-&gt;getConfigFor($feeds_source-&gt;importer-&gt;fetcher);
  $feeds_config['source'] = $url;
  $feeds_source-&gt;setConfigFor($feeds_source-&gt;importer-&gt;fetcher, $feeds_config);
  $feeds_source-&gt;save();
  $feeds_source-&gt;startImport();

  drupal_set_message(' .... ENDING IMPORTS-CRON CALL!');
}


Both the drupal_set_message() calls are successfully executed, but no node is imported.

Can anyone help, please?
Your code seems to be OK. I use some similar code in one of my projects (this a csv importer, similar concept):

function custom_function($importer_id, $csvfile_path) {
  // Load the Feeds Source object.
  $source = feeds_source($importer_id);
  // Load the source fetcher config.
  $fetcher_config = $source-&gt;getConfigFor($source-&gt;importer-&gt;fetcher);
  $fetcher_config['source'] = $csvfile_path;
  $source-&gt;setConfigFor($source-&gt;importer-&gt;fetcher, $fetcher_config);
  $source-&gt;save();
  $source-&gt;startImport();
}


Make sure that you are using the foreground configuration, this way the batch process could be be executed "inside" drupal with showing the progress bar. Or you can force it:

// Tweak the importer configuration, to enable "Process in the background".
$config = array(
  'process_in_background' =&gt; TRUE,
);
$source-&gt;importer-&gt;addConfig($config);

// Execute the import.


Another approach could be to schedule it

// Schedule the import, and make sure importer is scheduled, too.
$source-&gt;schedule();
$source-&gt;importer-&gt;schedule();


This is a good article about feeds importer