0

Hi trying to make an API call that triggers a postmaster update parcel

looked at this post

I'm called my plugin from at jquery ajax call , all working fine can update the entry with the db class

$updateQuery = ee()->db->
            update('exp_channel_data',
                array(
                    'field_id_85' => "tester"
                ),
                array(
                    'field_id_73' => $user['userdata'][0]['field_id_73']
                )
        );

But I would like to trigger postmaster (entry updated)

$this->EE->api_channel_entries->save_entry($data, (int)$user['userdata'][0]['channel_id'], (int)$user['userdata'][0]['entry_id']);

Like descibed in the post link above - but getting an error - do I need to login or is there another way to trigger a postmaster parcel ?

any help would be appreciated :)

1 Answer 1

0

Aha found out I have to be loggedin : ( using start , end session )

$this->startTempSession();

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

ee()->api_channel_fields->setup_entry_settings($channel_id, $edit_array);
$saveResult = ee()->api_channel_entries->save_entry($edit_array, $channel_id , $entry_id , FALSE);

ee()->session->destroy();

Start and session destroy :

public function startTempSession()
{
    $ee = ee();
    if (!class_exists('Channel_from_session')) {
        require_once PATH_MOD . 'channel/libraries/channel_form/Channel_form_session.php';
    }

    $tmpSession = $ee->session;
    $tmpSession->userdata['can_edit_other_entries'] = 'y';

    $ee->session = new Channel_form_session(array(
        'session_object'       => $tmpSession,
        'logged_out_member_id' => 1,
        'logged_out_group_id'  => 1
        ));
}

Please comment if there is a better way of doing this : just got here through trial n error ...

Your Answer

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

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