WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
Authentication and Create Post (2 posts)

  1. hreynolds2
    Member
    Posted 7 months ago #

    I am trying to use this JSON-API to create a post for my wordpress site from within a Ruby program.

    However, after a get a nonce and make the post call I get this response error:

    "error"=>"You need to login with a user that has 'edit_posts' capacity."

    How is a user supposed to "login" via a Ruby program? I am using the HTTParty gem for making my REST calls.

    Here is the code I am using:

    nonce_response = HTTParty.get "http://example.com/?json=get_nonce&controller=posts&method=create_post"
    puts nonce_response.code
    
    nonce_info = JSON.parse(nonce_response.body)
    puts nonce_info["status"]
    puts nonce_info["nonce"]
    puts nonce_info.inspect
    
    post_body = {:nonce => nonce_info["nonce"], :status => "draft", :title => "this is only a test", :content => "great content here!",
                 :categories => "Test"}
    
    post_response = HTTParty.post( "http://example.com/?json=create_post", :body => post_body)

    Thanks for any tips,

    --harris

    http://wordpress.org/plugins/json-api/

  2. atiniir
    Member
    Posted 6 months ago #

    Did you sort this out? i'm getting the same error

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.