GEO API Post

This topic contains 26 replies, has 3 voices, and was last updated by  Kiran 7 years, 11 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #341491

    Ray Zuchowski
    Expired Member
    Post count: 16

    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.

    #341957

    Kiran
    Moderator
    Post count: 7069

    Hi,

    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,
    Kiran

    #342092

    Ray Zuchowski
    Expired Member
    Post count: 16

    That plugin doesnt work, this is the console version that will load.

    https://wordpress.org/plugins/rest-api-console/

    #342093

    Ray Zuchowski
    Expired Member
    Post count: 16

    NVM the other one you sent i have to install composer.

    #342163

    Ray Zuchowski
    Expired Member
    Post count: 16

    Karin,

    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

    #342318

    Paolo
    Site Admin
    Post count: 31206

    Hi Ray,

    Kiran is off for the week end now, he’ll get back to you on Monday.

    Thanks,

    #343451

    Kiran
    Moderator
    Post count: 7069

    Hi 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 password

    Fill listing details & submit.

    Thanks,
    Kiran

    #348196

    Ray Zuchowski
    Expired Member
    Post count: 16

    Kiran,

    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}}

    #348353

    Kiran
    Moderator
    Post count: 7069

    Hi,

    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

    #348428

    Ray Zuchowski
    Expired Member
    Post count: 16

    Just 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 ?

    #348735

    Ray Zuchowski
    Expired Member
    Post count: 16

    Kiran,

    I solved the issue.

    The .htaccess file has to be changed to this.

    <IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule .* – [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.

    #348864

    Kiran
    Moderator
    Post count: 7069

    Great!

    Thanks for letting us know 🙂

Viewing 12 posts - 16 through 27 (of 27 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount