1

I'm having a bit of trouble getting Open API to work with EE in conjunction with the Channel Entries API. It seems to be a similar problem to this question:

https://expressionengine.stackexchange.com/questions/10933/open-api-500-internal-server-error

So pulling data with GET is fine, but POSTing data returns 500 errors.

The trouble seems to stem from using square brackets or round brackets to access session data. Open API uses the following format:

$this->EE->session->userdata['group_id']

Whereas EE in the channel entries API uses this format with the round brackets:

$this->EE->session->userdata('group_id')

I went through and edited all references with round brackets in /libraries/api/Api_channel_entries to the square brackets and that fixed the issue with Open API. I was able to GET and POST just fine.

But it messed up everything else with publishing entries via the EE control panel or with Safecracker.

Does anyone have any insight into the difference between accessing data in these 2 ways and how it might be affecting things? I'm not sure whether its an EE problem or PHP issue.

I'm running a local install of EE 2.5.2 with PHP 5.3.15 and I've also tried a fresh install of 2.6.1 and had the same issue.

1

I don't know how to fix your issues exactly, but I can help you with the EE logic in question.

If you look at the following file:

system/expressionengine/libraries/Session.php

You will notice that userdata is a public property and method. If you access the property, you get an editable associative array, whereas the userdata() method just returns a specific key from that array. If you look at the method itself, you will see it's actually just referencing the property.

/**
 * Fetch a session item
 *
 * @param   string      Userdata item to return
 * @param   default     value returned if the key isn't set
 * @return  mixed       $default on failure, item on success
 */ 
public function userdata($which, $default = FALSE)
{  
    return ( ! isset($this->userdata[$which])) ? $default : $this->userdata[$which];
}
  • Right, that makes sense and I think puts me on the track of finding the problem… I'm guessing the session isn't being set correctly by open-api which causes the method variation to fail. Or the session information is lost when accessed via the method. I'll dig deeper and see if I can figure it out. Thanks Justin! – willmcc Jul 23 '13 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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