REST API – Page 2

How to Upload an Image using WordPress REST API

In this tutorial, I am going to show three ways of how you can upload an image to a remote WordPress site using the REST API.

  • In the first way, we’re going to do it using WordPress HTTP API functions: wp_remote_post() or wp_remote_request(),
  • In the second way, I will show you how to do the same with cURL; why not?
  • Finally, in the third way, I will show you an example of how to upload media with the WordPress REST API using JavaScript.

The methods here are also used by my Simple WP Crossposting plugin, because, you know, when you crosspost a post to another site with the REST API, you definitely need to copy its images as well, at least the featured image.

All right, let’s just dive into it.

Get Product (or Variation) by SKU

In this tutorial, I will show you how to get a product or a product variation object in WooCommerce if you only know its SKU. When we just need to get a product object by ID, we use the wc_get_product() function – super-easy, right? But if we only have an SKU, it is going to be a little bit more interesting.

So, I am going to show you four different ways how you can obtain a product object from its SKU, we are going to do it both the WooCommerce way (with WP_Product_Query and wc_get_product_id_by_sku() function) and the WordPress way (with WP_Query). Also, I will show you how to do it when you interact with the WooCommerce REST API.

Sync Posts and Pages from Staging to Live Site

We all know about the export and import thing – when you move from staging to live the entire site at once. But from time to time I keep getting requests from clients about syncing only specific posts or pages (or custom post types – doesn’t matter).

In this guide, I am going to talk about two ways how we can achieve that – programmatically from scratch and with a WordPress plugin.

Create and Update Products with WooCommerce API

Recently, I was publishing and updating the tutorials about WordPress REST API, how to create a post, how to add a featured image and so on. But did you know that WooCommerce has its own API, which is built on the base of a regular WordPress REST API but allows you to do many more things and also simplifies the work with the other ones?

In this tutorial, we are going to dive into actual examples of working with WooCommerce API. I will show examples of creating and updating products, and also we will try to search them by SKU and delete them.

In this tutorial specifically, I am going to use two methods of interaction with the WooCommerce API – using WordPress HTTP functions like wp_remote_get() and wp_remote_request() and also using an official WooCommerce REST API PHP library.

Create or Update WooCommerce Orders via REST API

In this guide, we’re going to dive into different examples of both creating and updating WooCommerce orders using the REST API. By the way, if you’re looking for a way how to delete orders using REST API, check my other tutorial out.

Create a Post with WordPress REST API from Remote Website

In this tutorial, I will guide you through the process of creating a post with the WordPress REST API. First, we’re going to talk about authentication, then we will send an example REST API request, and finally, we talk a little bit about request parameters.

Get Featured Image in REST API

In this tutorial, I’d like to continue showing you some tips and tricks that can be useful when working with WordPress REST API, so I am going to show you two ways how you can get a featured image:

  1. If you know a featured image ID, you can always use the /wp/v2/media/{$media_id} endpoint, I am going to discuss this method first.
  2. Another story: if all you have is a post ID, and you need to get a featured image URL from it.