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   1278 Views

Avatar
dompie

Community Member, 88 Posts

28 September 2010 at 4:19am

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

Forum Moderator, 1798 Posts

28 September 2010 at 4:28am

Edited: 28/09/2010 4:29am

Is this what you are after?

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

Avatar
dompie

Community Member, 88 Posts

28 September 2010 at 5:03am

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

Community Member, 88 Posts

28 September 2010 at 11:37pm

Is there a way to use the api without login?

Avatar
dompie

Community Member, 88 Posts

29 September 2010 at 4:11am

Solved...simply use

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

Or do the curl-cookiejar way.