What I (or or customer) want to do is as follows:

  1. An existing external API has regularly updated documents for different products
  2. The existing product channel in EE will hold an ID that is recognised by the API and will return (amongst other things) the external path to the document
  3. The existing product channel also has an asset field (pixel & tonic) that is able to store the file locally
  4. Now I want to update that file regularly (eg every 24h) by downloading it and storing it in the asset field.

Any ideas how it can programmatically insert or update files in a chosen Pixel & Tonic Asset field?

rg, Tim

2 Answers 2


All files in asset fields are stored in a bunch of the exp_assets_* tables. You can insert/delete/update rows to make the changes you want. For instance, you can add new files to exp_assets_files, and update rows in exp_assets_entries and/or exp_assets_selections to make the assignments to entries.

Alternatively, you can include PATH_THIRD . "/assets/libraries/assets_lib.php" and then use some of the methods in Assets_lib() to handle adding to the appropriate rows.

Finally, you could also upload the items yourself and then force Asset to re-index the source by hitting their re-index ACT endpoint with the right data.


enter image description here

I would need more information, but for an initial quick reply on my assumptions, my instinct is that for importing and synching (as in not re-importing data but rather updating) the indispensable DataGrab might suit the bill. It allows you to import multiple formats, from RSS to XML and JSON, etc., and specify a key (think database index/key) so that duplicate keys won't be re-introduced to your database.

In your case you would be able to key the external unique identifier to your internal (EE) unique identifier, and thus not only import your records, but also update them if they change on the other side. Sweet.

As for the programmatic part: set a cron job to poll ExpressionEngine's native ?ACT=XX&id=XX urls and the system will update whenever you wish. ;-) If you're stuck with only having image URLs to work with but you wish to actually bring in the images, I believe that Causing Effect's CE Image will work with an external URL (fist time the page loads) and thereafter use the local file. So as long as you can get the image's URL into EE, you can have the system (via CE Image) pull it in for you. I don't know how I would integrate this with Assets, but I haven't actually thought that part through. I'm sure you'll be able to come up with something. :-)

I'm using DataGrab extensively on a client site to bring in RSS feeds of medical articles. I'm able to filter the incoming feeds to only import articles that contain certain words (since I don't want non-relevant articles) and it's superb, a deceptively simple-looking Swiss Army Knife of data import, and one I recommend highly.

Check it out!

  • Thanks for your reply! I'm familiar with DataGrab and although I believe it is great, it is not fit for purpose here I believe as there is not a full list that needs to be imported, but individual calls to the API will happen if the external product-ID is available. I'm not to worried about that part however, I'll will require custom programming but that's ok. For your information, what needs to be imported are documents not images and they need to be available locally for SEO reasons amongst other things I'm most worried about how to insert / update these documents in P&T asset fields Jun 26, 2014 at 9:26

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.