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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

API access and login


Go to End


5 Posts   1789 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, 1899 Posts

28 September 2010 at 4:28am

Edited: 28/09/2010 4:29am

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.