I'm trying to find a way to create an article in a Wordpress portal using a Java application I developed. I have some clients that need to publish on this portal, but it should be something automated by this Java application. Is there any way (plugin or api) that I can send a JSON to the Wordpress portal (POST) and publish the article? I thought about creating, inside my Java application, a JSON and sending it to the Wordpress portal, something like:
{"author": "John Doe", "title": "New article", "Content": "Lorem Ipsum ...", ...}
How can I do this?
I'm trying to find a way to create an article in a Wordpress portal using a Java application I developed. I have some clients that need to publish on this portal, but it should be something automated by this Java application. Is there any way (plugin or api) that I can send a JSON to the Wordpress portal (POST) and publish the article? I thought about creating, inside my Java application, a JSON and sending it to the Wordpress portal, something like:
{"author": "John Doe", "title": "New article", "Content": "Lorem Ipsum ...", ...}
How can I do this?
Share Improve this question asked Oct 16, 2018 at 14:02 aseolinaseolin 1132 bronze badges 1- Sounds like you're in need of the REST API – Tom J Nowell ♦ Commented Oct 16, 2018 at 14:06
2 Answers
Reset to default 3Yes, there is a REST API at /wp-json
with core content endpoints for posts pages etc
For example, my current latest blog post:
https://tomjn/2018/07/23/deployment-and-wordpress/
Is available via a GET
request as a JSON object at:
https://tomjn/wp-json/wp/v2/posts/862
And I can send a similar object via an authenticated POST
request to create a new post to https://tomjn/wp-json/wp/v2/posts/
, or a HTTP UPDATE
or DELETE
request.
Note that WP includes an auth method out of the box that requires a nonce and a cookie of a user capable of creating posts in order to do this. For external applications, you will need a plugin to implement OAuth1/2 or another authentication scheme of your choosing
I think you're asking about WordPress REST API. From The Handbook:
The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects. It is the foundation of the WordPress Block Editor, and can likewise enable your theme, plugin or custom application to present new, powerful interfaces for managing and publishing your site content.
The linked documentation above should have all the resources you need to build something like what you're looking for.