I have a Drupal 7 website that is intend to be fed by a JSON file. This file, is actually processed and updated by a ETL tool that runs periodically (each 3 hours by example).

Once my ETL tool has processed the output JSON file, I need a way to tell the Drupal Feeds module to start the import.

Is it possible ? Or do I need to do this with CRON ?

Ideally, this job would be trigged by a specific URL call (just like the CRON can be called manually by visiting a specific url).


Based on @Gaydabura clues, I've created a module. Here's the answer :

1. use hook_menu to define you own path

function toot_menu() {
  $items = array();
  $items['toot/import'] = array(
    'page callback' => 'toot_callback',
    'title' => 'Import tool',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  return $items;

2. write function using docs to parse your data

function toot_callback($key = '') {
  if ($key != 'defined_key') {
    return t('Unauthorized access');
  else {
    $myFeed = feeds_source('feed_unique_id');
    while (FEEDS_BATCH_COMPLETE != $myFeed->import());
    return t('Import successfull');

For triggering a feeds importer programmatically -

1) Load the feeds source using feeds_source() - by passing argument importer id [it is the machine name of the importer; you can find it in the table 'feeds_source']

$feeds_source = feeds_source([importer_id]);

2) Set up the configuration -

$feeds_config = $feeds_source->getConfigFor($feeds_source->importer->fetcher);
$feeds_config['source'] = $url;//url of file | url of site

3) Set configurations to feeds source

$feeds_source->setConfigFor($feeds_source->importer->fetcher, $feeds_config);

4) Start the import


I have implemented this for fetching data from url. Haven't tried with file, but this should work with may be some minor changes in the config part.

Else I think you can trigger the feeds using cron too. Elysia Cron is a great module which gives 'fine grain control over each task and several ways to add custom cron jobs to your site'.

I hope this is of help.

  • this is basically what I've done. What I couldn't find was the configuration part ! Thanks for sharing. – Jean-Michel Garcia Jan 17 '13 at 12:46
  • Do you know the difference between startImport() and import() ? – Jean-Michel Garcia Jan 17 '13 at 13:45
  • 1
    @Jean-MichelGarcia I haven't yet found what import() does. Btw, this is a great article on programmatically executing a feeds importer - nodesforbreakfast.com/article/2012/09/23/… – SGhosh Jan 18 '13 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.