Bug #23714 See Comments

ExpressionEngine Channel Entries API throws error

Version: 4.3.4 Reporter: Joshua Bunting

I created some code to test the API in EE v4 but it throws an error. I know this is based on the new v4 database structure and it looks like the legacy API hasn’t been updated. Example of what I created and the result:

Template (PHP Enabled):

<?php

error_reporting(E_ALL);

ee()->load->library('api');
ee()->legacy_api->instantiate('channel_entries');

$myip = $_SERVER['REMOTE_ADDR'];
                $updateddata = array();
                $updateddata["title"] = 'This is a test';
                $updateddata["url_title"] = 'this-test';
     $updateddata["field_id_1"] = 'This is a test';

     $resultPub = ee()->api_channel_entries->save_entry($updateddata, '1', null, false);

?>
Exception Caught

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_id_1' in 'field list':
INSERT INTO `exp_channel_data` (`entry_id`, `channel_id`, `site_id`, `field_id_1`, `field_ft_1`) VALUES ('1', '1', 1, 'This is a test', 'none')

ee/legacy/database/drivers/mysqli/mysqli_connection.php:116

Stack Trace: Please include when reporting this error

#0 ee/legacy/database/drivers/mysqli/mysqli_driver.php(111): CI_DB_mysqli_connection->query('INSERT INTO `ex...')
#1 ee/legacy/database/DB_driver.php(269): CI_DB_mysqli_driver->_execute('INSERT INTO `ex...')
#2 ee/legacy/database/DB_driver.php(179): CI_DB_driver->simple_query('INSERT INTO `ex...')
#3 ee/legacy/database/DB_active_rec.php(1370): CI_DB_driver->query('INSERT INTO `ex...')
#4 ee/legacy/libraries/api/Api_channel_entries.php(1221): CI_DB_active_record->insert('channel_data', Array)
#5 ee/legacy/libraries/api/Api_channel_entries.php(173): Api_channel_entries->_insert_entry(Array, Array, Array)
#6 ee/legacy/libraries/Functions.php(626) : eval()'d code(15): Api_channel_entries->save_entry(Array, '1', 0, false)
#7 ee/legacy/libraries/Functions.php(626): eval()
#8 ee/legacy/libraries/Template.php(2005): EE_Functions->evaluate('{!-- ra:0000000...')
#9 ee/legacy/libraries/Template.php(585): EE_Template->parse_template_php('{!-- ra:0000000...')
#10 ee/legacy/libraries/Template.php(231): EE_Template->parse('{!-- ra:0000000...', false, 1, false)
#11 ee/legacy/libraries/Template.php(164): EE_Template->fetch_and_parse('', Array, false)
#12 ee/legacy/libraries/Core.php(670): EE_Template->run_template_engine('', '')
#13 ee/legacy/controllers/ee.php(62): EE_Core->generate_page()
#14 [internal function]: EE->index()
#15 ee/EllisLab/ExpressionEngine/Core/Core.php(240): call_user_func_array(Array, Array)
#16 ee/EllisLab/ExpressionEngine/Core/Core.php(109): EllisLab\ExpressionEngine\Core\Core->runController(Array)
#17 ee/EllisLab/ExpressionEngine/Boot/boot.php(146): EllisLab\ExpressionEngine\Core\Core->run(Object(EllisLab\ExpressionEngine\Core\Request))
#18 index.php(172): require_once('...')
#18 index.php(172): require_once('...')
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases