I need to create a CSV dump/feed whenever a new item of "Content Type A" is created, with only that new item's info in the CSV. How can this be accomplished? For example, if 100 new items of "Content Type A" were created today, there would be 100 separate CSV files with the field values for each of those content items.


1 Answer 1


Look at Views Data Export. It can create a CSV from Node content.

It sounds like you need this to somehow be recurring over time ... this is a tall order and so I wont be providing much code, but will outline a possible solution:

  • Implement hook_cron_queue_info(). This is a cron task that runs off of a custom Queue. You can insert a NID every time a node is created into a custom queue you've created named MyCSVQueue. Every time a node is created it gets added to this queue -- when you process the queue you create individual csv files.
  • Use either hook_node_insert or Rules to place the NID into the work queue.
  • In your queue worker function you pass the NID to a custom view that uses a contextual filter to load the NID. Or, you may be able to use node_export to create the CSV data as well. You then simply use the Drupal File API and file_save() to store the csv file somewhere in your public/private drupal filesystem.

If the default Cron options of drupal dont suite your needs look at Ultimate Cron


A slightly easier alternative:


  • Use either hook_node_insert or Rules to run a snippet of custom PHP code. Simply create a file directory using the File API in public files as: %files/csv_node_exports/MM-DD-YYYY. Your snippet can create the directory if it doesnt exist today yet.
  • then just export the node data to a CSV file. You may or may not have a NID yet ... you could always update the filename after the fact to reflect the actual NID assigned to the node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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