GEO API Post
This topic contains 26 replies, has 3 voices, and was last updated by Kiran 7 years, 10 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: api
-
AuthorPosts
-
January 12, 2017 at 3:53 pm #341491
Karin,
So i disabled the authentication and im still getting a 401 error code when trying to POST. Is there something in the API that is protecting this ? If i do a POST from the API Console in wordpress i can do it successfully. Im testing this through Postman.
January 13, 2017 at 8:09 am #341957Hi,
Install plugin https://github.com/WP-API/OAuth1 ( https://wordpress.org/plugins/rest-api-oauth1/ )
This plugins add 3 endpoints for authentications under route “oauth1”
authentication": { "oauth1": { "request": "http://www.yoursite.com/oauth1/request", "authorize": "http://www.yoursite.com/oauth1/authorize", "access": "http://www.yoursite.com/oauth1/access", "version": "0.1" } }
The token variable need to set in http request header when making ajax call.
For ex:$.ajax({ url: 'http://www.yoursite.com/wp-json/wp/v2/posts/1', method: 'POST', beforeSend: function ( xhr ) { xhr.setRequestHeader( 'Authorization', 'OAuth oauth_consumer_key=m045BGCecGnT, oauth_nonce=8Biih2, oauth_signature=ibV%2FQq0m7vDC3NrdCo%2BAVmM5Xcc%3D, oauth_signature_method=HMAC-SHA1, oauth_timestamp=1484293880, oauth_token=Uzy2pdmWMVDBznZ3q8iFbB19' ); }, data:{ 'title' : 'Hello Moon' } }).done( function ( response ) { console.log( response ); });
Please check this example https://github.com/WP-API/api-console which using REST API + OAuth1 plugin.
Thanks,
KiranJanuary 13, 2017 at 2:48 pm #342092That plugin doesnt work, this is the console version that will load.
January 13, 2017 at 2:59 pm #342093NVM the other one you sent i have to install composer.
January 13, 2017 at 5:40 pm #342163Karin,
Ok after installing everything, cli -console doesnt work with the new oauth 1.0a . Rather then using oauth, can your api use basic ? Im at a stand still here. Or what else do you recommend i do ?
Thanks
January 14, 2017 at 12:33 am #342318Hi Ray,
Kiran is off for the week end now, he’ll get back to you on Monday.
Thanks,
January 16, 2017 at 10:43 am #343451Hi Ray,
Our GeoDirectory REST API plugin follows WP standard functions for all REST API requests. So you can use any 3rd party plugin or code for REST API authentication.
Please check attachment, i have created sample example to submit listing via POST method by using Basic Authentication.
1) Installed Basic-Auth plugin – https://github.com/WP-API/Basic-Auth
2) Extract geodir-rest-api-example.zip in wordpress root folder.
3) Browse url http://www.yoursite.com/geodir-rest-api-example/
4) Fill values
api_url => Your json api url ex: http://www.yoursite.com/wp-json (without back-slash)
username => user login
password => user passwordFill listing details & submit.
Thanks,
KiranJanuary 24, 2017 at 12:18 am #348196Kiran,
Thank you for the example. I did exactly what you told me to do and this is the response i get.
{“code”:”rest_cannot_edit”,”message”:”Sorry, you are not allowed to edit this post.”,”data”:{“status”:401}}
January 24, 2017 at 4:15 am #348353Hi,
Let me know.
1) Are you going to add/edit post as an administrator or an normal user?
2) The user credentials being used is the owner of listing? (If you are going to edit listing)Kiran
January 24, 2017 at 10:53 am #348428Just editing the post, i used the users credentials for the listing, i also tried admin credentials as well and got the same result. Could it be something on the .htaccess causing this ?
January 24, 2017 at 9:38 pm #348735Kiran,
I solved the issue.
The .htaccess file has to be changed to this.
<IfModule mod_rewrite.c>
RewriteEngine OnRewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ – [L]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>Also a user has to be set to author.
January 25, 2017 at 4:05 am #348864Great!
Thanks for letting us know 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket