Magmi Datapump API

From Magmi Wiki
Jump to: navigation, search

What is Datapump API

Datapump API is a way to use magmi with totally custom PHP scripts. The idea is to enable developers to feed magmi with PHP arrays as if they were CSV lines.

Another idea behind Datapump API is to be able to recall existing magmi profiles.

Sample Datapump API integration script example importing 100 fake items

<syntaxhighlight lang="php">

// assuming that your script file is located in magmi/integration/scripts/somedirectory/myscript.php,
// include "magmi_defs.php" , once done, you will be able to use any magmi includes without specific path.
//Datapump include

// create a Product import Datapump using Magmi_DatapumpFactory

// Begin import session with a profile & running mode, here profile is "default" & running mode is "create".
// Available modes: "create" creates and updates items, "update" updates only, "xcreate creates only.
// Important: for values other than "default" profile has to be an existing magmi profile 

//loop over 100 fake items
 // Here we define a single "simple" item, with name, sku,price,attribute_set,store,description
 // some varations on sku , name & description based on loop index
 $testitem=array("name"=>"test item $i","sku"=>"SKU". str_pad((int) $i,4,"0",STR_PAD_LEFT),"price"=>"10.00","attribute_set"=>"Default","store"=>"admin","description"=>"ingested with Datapump API - item $i");

 // Now ingest item into magento

// End import Session

// Look for further examples in "magmi/integration/samples"



  • Your custom script has to include "magmi/inc/magmi_defs.php" and then "magmi_datapump.php"
  • If you put your scripts in the folder "magmi/integration/scripts/yourdirectory" you may include these two files like shown in the example above.
  • The item array should have keys that match CSV columns that are compatible with magmi ingest (ie: any attribute code,+ store & attribute_set (in create mode),+ specific plugin columns if used in the wanted profile)

More Examples

Look for further examples in the folder "magmi/integration/samples". Provided examples demonstrate how to create upsell, cross sell, and related items and how to get the log data from magmi introducing a custom logger class.

What is possible

In fact, anything is possible. Using Datapump API you can:

  • Read totally custom files (like XML feeds) in PHP, build an item array from the XML values
  • Read external databases , use SQL result as item to be ingested
  • Download remote files , read them & build item array content to be ingested.
  • Whatever you want