WordPress.org

Forums

JSON API
How can I create Post (4 posts)

  1. sailen.wms
    Member
    Posted 1 year ago #

    How can I create post can any one give me a example?

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

  2. HwangC
    Member
    Posted 12 months ago #

    Please refer to the following code.

    you need to generate the nonce first to create a post.

    $.ajax({
    	// get the nonce
    	dataType: 'jsonp',
    	url: '/api/get_nonce/?controller=posts&method=create_post',
    	type: 'GET',
    	success: function  (data) {
    		// create the post
    		$.ajax({
    			url: '/api/create_post/',
    			type: 'POST',
    			dataType: 'jsonp',
    			data: {nonce: data.nonce, status:'xxxx',title:'xxxx', content:'xxxx'},
    			success: function  (data) {
    
    			},
    			error: function  (data) {
    				console.log('error');
    			}
    		});
    	},
    	error: function  (data) {
    		console.log('error');
    	}
    });

    nonce is the key for creating a post.

  3. greenfireco
    Member
    Posted 12 months ago #

    Hey, thanks! I'm trying to figure out the same thing.

    How would we go about executing this code? I want to pull JSON feed from an external site. So I understand that I would then replace:
    "url: '/api/get_nonce/?controller=posts&method=create_post',"
    with my external feed with API key? Or where do we place the source url?

    And the other part, is with the data:
    data: {nonce: data.nonce, status:'xxxx',title:'xxxx', content:'xxxx'},
    Do we replace the 'xxxx' with JSON field names? And is it possible to add custom fields to the string?

    Thanks and I know this is a lot but I'm really new to JSON and JQUERY, and I can kind of figure it out but just missing the right people to ask!

  4. Tom Fischer
    Member
    Posted 11 months ago #

    I believe you need to be able to be authenticated with permission to create a post. For that, you can use the json api auth. There is some more information here:

    http://wordpress.org/support/topic/error-you-need-to-login-with-a-user-that-has-edit_posts-capacity

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.