Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

API access and login


Reply

5 Posts   1272 Views

Avatar
dompie

28 September 2010 at 4:19am Community Member, 88 Posts

Hello,

I'd like to use the Restful API for one of my Objects. It works all great when I login with the browser. But how do I login using a HTTP GET with Silverstripe? Do I have to use curl to make a POST on the login form (http://my.domain.com/Security/login...) before accessing the API? Any other solution?

I only receive an empty

<DataObjectSet totalSize="6"></DataObjectSet>


when I'm logged out.

Avatar
swaiba

28 September 2010 at 4:28am (Last edited: 28 September 2010 4:29am), Forum Moderator, 1796 Posts

Is this what you are after?

http://www.mysite.com/Security/LoginForm?action_dologin=1&Email=Admin&Password=Admin&BackURL=urlsegment/

Avatar
dompie

28 September 2010 at 5:03am Community Member, 88 Posts

Well, not really. Your solution works in a browser, because it accepts Session/Cookie data. But when you try that with file_get_contents(), it will fail because of the redirect after a successful login. Therefore it will be neccessary to use curl to survive the redirect and remember Session/Cookie data.

I'm interested in a solution that allows the use of file_get_contents(http://myurl.de/api/v1/MyObject/)

Avatar
dompie

28 September 2010 at 11:37pm Community Member, 88 Posts

Is there a way to use the api without login?

Avatar
dompie

29 September 2010 at 4:11am Community Member, 88 Posts

Solved...simply use

canView($member = null){
return true;
}

Or do the curl-cookiejar way.