Use API on a WordPress site - wordpress

Hello stackoverflow friends 🙂
I want to make a portal in wordpress with the Zabbix API. Can I do it in the WordPress platform itself or do I have to write the code elsewhere?
Is this possible?
Does anyone ever tried to do this kind of stuff?
Is there a plugin to call APIs?
I really need an answer to know if it is possible to do this type of things or if I need to look for another type of CMS’s.
Thanks and good work!

Yes it is possible to use that API in WordPress. You can create it as a plugin. Here's more details on how to create a plugin, from the official documentation : https://developer.wordpress.org/plugins/
To make the API calls, have a look at the HTTP API : https://developer.wordpress.org/plugins/http-api/
To do database interactions(like saving the data to your db or fetching it), have a look at the wpdb class : https://developer.wordpress.org/reference/classes/wpdb/
If you want to run cron jobs (scheduled tasks), please have a look at the WP-Cron: https://developer.wordpress.org/plugins/cron/
There are several built functions, hooks and classes in WordPress that will aid you. Just go through the developer documentation provided by WordPress.

Related

Display products from Woocommerce in external application

I have a question about integration e.g. Woocommerce with external app.
What is the best and safe method to accomplish this goal?
Woocommerce has REST API but it might be quite vulnerable and will not show anything (products etc.) to non logged user(which is understandable).
Only safe idea that's comes to my mind is creating scripts inside WordPress and access them via AJAX but I'm worrying about performance of this method.
Maybe there is a right way that I'm not familiar with?
For that purpose, you should create an API from scratch of the wordpress database. wordpress databse has all of you need in a good way and only some php codes needed to create and execute the API. then in you app with AJAX you should access that.
this link may help you:
https://developer.okta.com/blog/2019/03/08/simple-rest-api-php
The right way is likely creating your own API if you don't want to use Woocommence's one. That means you make a plan of what you need to expose, all the routes and start building the API. I warmly recommend the book by Phil Sturgeon - Build APIs you won't hate. The author is also a co-founder of https://phptherightway.com/ so it's quite reputable.

Creating a WordPress plugin that uses the HTTP API to connect to external API

I am trying to build a plugin that connects to an API to fetch a list of products and display information about each of them. I understand that I will most likely use the HTTP API provided from WordPress, but I found the documentation very vague and I don't know where to start. I searched for other materials on this matter but I couldn't find anything related to WP plugins that get data from external APIs.
Does anyone know any good resource about this or have any suggestion about what steps I should follow?
EDIT: What I am looking for is maybe an example of how the WP HTTP API is used in a WP Plugin. I have searched everywhere but all I can find is the WP REST API and that is something completely different from what I am looking for.
This post on Sitepoint is a bit old, but still does a pretty good job at explaining the different parts of the HTTP API: https://www.sitepoint.com/the-wordpress-http-api/
Just be sure to look up the functions mentioned there to see if they changed in the past four years.

WP-API - How get post resource by name instead ID?

I'm developing a system integration java webapp - wordpress CMS. I adopted the WP-API plugin.
In my case i have some codes in JSPs like.. for example using JSTL:
<c:import url="[[host-wordpress]]/wp-api/post/44888">
However, if a wordpress user recreate the post consequently broken my integration.
Also would be intuitive for java frontend programmer find a code like :
<c:import url="[[host-wordpress]]/wp-api/post/news-about-something">
I saw in wp-api documentation that is possible by WP-QUERY, however i would like to implement a less invasive method.
Anybody knows how to do that ?
I forked wp-api and I added a new method :
https://github.com/dufabricio/WP-API/commit/3c3399c9a613143590d38df06a8f4c4848b21627
I don't know if it is the better way, but this method solves my issue by now :)

wordpress java xml rpc library and/or client

Can anyone recommend an xml rpc library or client for wordpress using java?
I've run into migration hell moving a joomla install to wordpress.
Main reason for wanting to use rpc now is because i will be using it as my primary way of posting to the blog so i'm putting a simple client together and it needs to be configurable enough to allow me to port my joomla posts.
Some posts in future will just be reports generated from a java program as well so, its kinda essential i get something now if possible.
BTW if anyone understands the current wordpress table structure and can advise on how to do direct mysql inserts then i'm open to that too.
thanks in advance.
Have a look at http://code.google.com/p/wordpress-java , I've just added a few features.
I've just posted this link on a different WordPress question:
Database Description from WordPress Codex. That will help you understand WordPress' table structure.
Your project sounds pretty interesting. A quick google search shows some info on Java and XML-RPC: 1, 2 (javax.xml.rpc ).
Second link belongs to Apache XML-RPC, probably a good option for your project.

Wordpress XMLRPC advice needed

I have been tasked with creating an API for retrieving and adding content to Wordpress from a flash application and legacy CMS (non-PHP). My plan is to utilise the existing default xmlrpc endpoint and add any additional functionality by creating a plugin which hooks into xmlrpc_methods.
A previous attempt had been made by another developer based on the following code:
http://blog.5ubliminal.com/posts/remote-control-wordpress-blog-xmlrpc-api/
This code looks unwieldy and poorly documented to me and my preference would be to use this approach:
http://kovshenin.com/archives/custom-xml-rpc-methods-in-wordpress/
I would be grateful if anyone with experience in this area could confirm that:
I will be able to distinguish between separate blogs in an MU installation when both retrieving and posting data via XMLRPC
I will be able to retrieve and post to custom fields
writing a plugin is the way to go.
We do not have the option of using Wordpress 3 as it is still in Beta and we are under time pressure.
I would greatly appreciate appreciate any input / advice.
Many thanks,
I've worked with WordPress' XMLRPC system before (using a WP-Hive installation with multiple separate blogs similar to a WPMU set-up). The new approach you're using is definitely simpler and easier to implement (I tried the 5ubliminal one as well the first time).
Whether or not you can distinguish between separate blogs in a MU installation depends entirely on how you build your handler function. You can build it to distinguish the separate blogs, to only function on specific blogs, or to treat the entire system as a single WordPress site. It's all up to you.
By "handler function" I mean a custom function you define to handle XMLRPC requests that call a specific, custom method (not necessarily the default WordPress methods). For example, I use XMLRPC in all my plug-ins to report back installation progress and errors -
each plug-in makes an XMLRPC call to a custom handler (method) on my server.
Yes, you can retrieve and post to custom fields.
Absolutely writing a plug-in is the way to go. The only other options are to change core files (BAD idea) or to build it into your theme, in which case it could ONLY be used on MU sites using that theme. Build it as a site-wide MU plug-in that can be controlled on a site-by-site basis by the global admin.
Wordpress XMLRPC offers various functionalities which can be harvested easily. I have used IXR_Library to parse the XML requests/responses. Currently with very small piece of code i can easily posts, fetch, edit and delete Posts in Wordpress based blogs either self hosted or on wordpress.com sites.
http://www.hurricanesoftwares.com/wordpress-xmlrpc-posting-content-from-outside-wordpress-admin-panel/ (reference)
When you have multiple blogs hosted via MU you will need site ID of all those blogs which will become the first parameter for $params (in our case 0 should be replaced with site_id).
In the reference i gave above you will see the option to fetch and post to all created custom fields (unfortunately, you can't create custom fields on the fly from my script)
You are welcome to write a WP plugin to do all of this, be my guest and let me know if you need my help. I have used the same technique to post to blogger, tumblr, Wordpress and Posterous using their API's. I hope this helps.

Resources