2

I got this error The requested URL /wp/v2/posts was not found on this server.

when trying to post a new post using WP api in node.js.

var WPAPI = require('wpapi')

var wp = new WPAPI({
    endpoint: 'http://example.com',
    username: 'test',
    password: 'test'
})
wp.posts()
    .create({
        title: 'Your Post Title',
        content: 'Your post content',
        status: 'publish'
    })
    .then(function(response) {
        console.log(response.id)
    })
    .catch(function(err) {
        console.log(err)
    })

The code is taken from here https://github.com/WP-API/node-wpapi

What's the possible causes of the issue? I'd tried to change the permalink to postname.

Hoknimo
  • 533
  • 2
  • 6
  • 15
  • are you sure about domain you entered is correct? in your code it's example.com? – MJN Nov 09 '18 at 05:36
  • @Manjunath domain is correct. I can login, and use wp.get() for posts but can't create a new post. – Hoknimo Nov 10 '18 at 16:11
  • I got this working by appending /index.php/ in URL before wp-json. I.e. http://localhost/myproject/index.php/wp-json/wp/v2/posts See similar answer [here](https://stackoverflow.com/questions/34670533/wordpress-rest-api-wp-api-404-error). – RonanOD Jun 19 '19 at 17:32

0 Answers0