Search code examples
expressionengine

creating an Expresison Engine post via the API


I'm trying to create a post in an Expression Engine powered website via an automated script, but as I've never used EE myself before, this is proving to be a more complicated task than initially expected!

I was originally just going to dump into the datbase directly, but it looks like there are multiple tables storing post data so rather than try to figure out what to dump where and hope EE never changes the structure, I'm thinking a better approach would be to use it's API, which I also didn't know existed.

https://docs.expressionengine.com/latest/development/legacy/api/api_channel_entries.html#Api_channel_entries::save_entry makes this look simple enough, but obviously ee() doesn't exist yet to my standalone script...

How would I go about initiating an ee() class from a script outside of Expression Engine itself, so that I can create posts directly?

This is EE 2.8 if that makes a difference.

Much appreciated.

Regards.


Solution

  • Here's an existing similar Stack Exchange answer, basically look at the index.php to see how they have natively instansiate the entire EE application. But it's recommended you don't for security reasons!

    Instead you could consider:

    • Writing a simple Extension to catch an endpoint URL via a hook and use the API from within EE (correctly) which would have been passed POST or restful data.
    • Load a channel form from a page on the EE site (server side or Ajax) and then utilise it's values to submit to another page on the EE site to create/edit an entry
    • See if it already exists in a restful API add-on (EE2 & EE3)
    • It's not actually that hard to modify the database, and EE2 will no longer have any updates so the data structure won't change (generally only channel_titles & channel_data, but depends if you have grid and category data also). But this is a security issue!