Topics

Tribe Support

Tribe Support's Topics

Victor Eberechi

January 28 2014

Restful Registration API.

I and my team mate want to use Anahita as the social backend for our mobile app. We like to register users with the RESTful Api. I have searched for examples on how this is done in Anahita but can't find any. Can anyone help here or point me to the right documentation on Anahita RESTful Api?

Thanks, Victor

Pavel Kulbakin
Pavel Kulbakin
January 28 2014 Permalink
Documentation is it's very early stages, only a handful topics covered and in very basic way. There is no RESTful API docs to my knowledge, the only way is to discover REST interface features for yourself looking into working features and source code.
Rastin Mehr
Rastin Mehr
January 28 2014 Permalink
https://github.com/anahitasocial/anahita/blob/master/src/site/components/com_people/controllers/session.php

Actions: read, add, post, and delete  

Also look at how the authentication and registration forms work. You just need to add format=json to your requests.

In general all Anahita controllers provide BREAD operations (Browse, Read, Edit, Add, Delete) as well as additional actions that might exist in the controller. Following that convention, you should be able to understand the RESTful API in all controllers.
Thanks for the responses. This sure helps us.

Victor
Victor Eberechi
February 07 2014 Permalink
We have spent lots of hours trying to get a user registered via the REST registration API. The user registration REST API is the reason we decided to use Anahita for our school project, but in the absence of documentation, we are spending an unexpected amount of time getting it to work. I'm posting this for a little help from any one who has worked with the registration API.

I'm using curl as a client to send the post request for now. This is just for testing and we will be using ajax calls in the mobile app. We keep getting the "Permissions denied page" after trying the below and a few more:

curl -X POST -H "Content-Type: application/json"   -d '{"name":"foo foo","username":"foousername", "email":"foo@foomail.com", "password":"abcd123abcd"}' http:///index.php/people/person 


curl  --form "name=foo foo&username=foousername&email=foo@foomail.com&password=abc123abc123&format=json" http:///index.php/people/person 

We have tried several combination of curl options and still get the pemission denied.

Can someone please provide an appropriate REST call format to register users on Anahita. We will appriecate it.

Thanks
Victor
Pavel Kulbakin
Pavel Kulbakin
February 07 2014 Permalink
you need to emulate the same response browser sends when submitting signup request. i suggest you make sure registration via browser works on your installation and then send request in exactly the same format browser does.
Victor Eberechi
February 07 2014 Permalink
Thanks Pavel for your respone. I have verified that registration works via the browser. From my previous comment, the curl examples are my attempt at sending the registration request like the browser does. Do you have any suggestions ? 

Since REST registration API is stated as a feature of Anahita, I believe someone has registered a user via REST at least at testing level. Can someone please provide a sample code on how to register a user with the following information:

Name : foo_first foo_last
username : foo_username
email address: foo@foomail.com
password: foo_pass

I don't mind if the code is in AJAX or curl. This will save me the next 4 hours. 

Thanks,
Victor.
Pavel Kulbakin
Pavel Kulbakin
February 07 2014 Permalink
browser does not send json for sure, as for curl  --form "name=foo foo&username=foousername&email=foo@foomail.com&password=abc123abc123&format=json" http:///index.php/people/person i don't know if this is equivalent of HTTP POST
Umesh
Umesh
February 07 2014 Permalink
I tried reconstructing cURL command using Chrome browser (Inspect Element -> Network -> copy as cURL) and below command worked for me

curl "http://website.com/people/session" -H "Referer: http://website.com/people/session?return=aHR0cDovL2dlZXRtYW5qdXNoYS5jb20vaW5kZXgucGhw" --data "return=aHR0cDovL2dlZXRtYW5qdXNoYS5jb20vaW5kZXgucGhw&username=user&password=pwd&Submit=&format=json" -X POST 

This doesnt respond anything except the next URL (with 303 code) which is http://website.com/index.php 

cURL doesn't work (in context of Anahita) without Referer
We are calling Login API from localhost

$http .post( "http://www.letsride.in/people/session.json?format=json", data, config) .success( function(data, status, headers, config){ $scope.message = "success"; }) .error(function(data, status, headers, config) { switch (status) { case 401: $scope.message = data.message; break; } });

But no success... any one can help on this... We are using angular JS
@rajkumar i guess you run into cross domain restirctions, gneerally you can't post to another domain, try to host your mobile application on the same domain as main anahita website
localhost to localhost is working.... But localhost to Letsride.in is not working... there should be any workaround for this... we are using angular JS
or try Access-Control-Allow-Origin might help
tried to set but no luck... both side..CLient and Sever side PHP (Session.php) also.. no luckWe have problem in POST ... GET is working fine
this is classic cross domain restriction, if Access-Control-Allow-Origin does not help, you mort likely set it up wrong (e.g. i don't see it when i open letsride.in)
Where we need to check the port and which port ?We are trying POST with Firefox Poster AddOn and Login POST API working perfectly and it aunthenticate and return object of logged In user....If this Firefox Poster AddOn can do , we should also able to do.. right ?
I am trying to implement login REST call with  people/session.json and posting username and password in post method via postman rest client, I am getting a issue like invalid referrer with code 402. Could anybody help me sorting this out
Ngoc-Tung Nguyen
February 15 2016 Permalink
I too am having the "invalid referrer with code 402" Could anybody help me ?
Rastin Mehr
Rastin Mehr
February 15 2016 Permalink
Start a new topic. If it is a bug, it will be fixed in the upcoming release. Describe what parameters you are posting and where. Also make sure that Access-Control-Allow-Origin on your servers is configured correctly https://michielkalkman.com/snippets/nginx-cors-open-configuration.html #cors

Powered by Anahita