Hi there,
I'm trying to expose some aspects of my Member object to a 3rd party through the RESTful Server API. The 3rd party needs to be able to create members and update existing members with some data in an additional column called "CompetitionEntryURL".
I've created the additional column in the Member object by using the extraStatics method of a class that extends the DataObjectDecorator like so:
class MemberDecorator extends DataObjectDecorator {
//Add extra database fields
public function extraStatics()
{
return array(
'db' => array(
'CompetitionEntryURL'=>'Text'
)
);
}
}
That bit works great.
Then I'd like to expose the Member object via the RESTful Server API and it is at this point I strike some problems:
- - Rather than extend the Member class, I tried simply exposing the MemberDecorator by also setting $api_access = true in the extraStatics function.
That however doesn't provide access to the actual member objects through REST, my instincts were that the DataObjectDecorator mechanism didn't seem right for this anyway.UPDATE: This did actually work, see my next post - - I then created a subclass of Member called MemberEx and enabled it through REST by setting the $api_access static with the appropriate permissions to ensure I'm only exposing columns and functionality that are appropriate. This works great adding Members via REST. The problem of course then is that all existing members in the database aren't of type "MemberEx" so their new CompetitionEntryURL column can't be edited through REST. This is despite the fact that CompetitionEntryURL is a column of the Member object (via the aforementioned MemberDecorator). Any new members added through here are of class type "MemberEx" and so their CompetitionEntryURL can be updated no problem. The other problem I have is that when I attempt to add a member who already exists through the exposed MemberEx class it simply returns a HTTP 500 header because it fails validation, fair enough, but I'd love to be able to create a custom method via REST that can be passed an email address so I can return an actual memberid if the member already exists.
- - Ideally I'd just enable $api_access on the inbuilt member object itself, with the required permissions of course, but that doesn't seem possible (nor does it seem appropriate). In any case $api_access is a static so I tried setting Member::api_access = true; in _config.php but that doesn't work.
Really all that serves as background. I think my issues could be resolved by simply having the ability to call a custom method via the RESTful Server API.
e.g. http://www.servername.com/api/v1/MemberEx/<METHOD_NAME>
However this doesn't seem possible, I can call a simple method in an instance of the MemberEx class by
http://www.servername.com/api/v1/MemberEx/<ID>/<METHOD_NAME>
Note the addition of <ID>, which is really the problem because what I'm after is more like a static method of the MemberEx class that can be called over REST without being tied to an instance of the class.
I also can't see how you would POST parameters to a custom method.
Of course I could use the SOAPModelAccess to define a SOAP method, but the documentation on that isn't great and I simply can't get it to work.
BTW. Thanks to Willr for assisting me on this, helped me get part the way there with not so much information from me.
Regards,
Adrian