Fetching & Updating AIOSEO Data via the WordPress REST API

The REST API addon (introduced with AIOSEO 4.1.9) is available for all Plus, Pro and Elite plan users and allows you to easily fetch and update AIOSEO data via the REST API.

This can be particularly useful when you for instance have:

  • A headless WordPress site where you need to manually output your SEO data on the frontend;
  • A 3rd party system to manage your posts (e.g. eCommerce ERP with WooCommerce integration) and would like to be able to manage your SEO data via that system.

Below we’ll explain which data is available via the REST API and how you can update it.

Fetching data

Instead of registering custom endpoints, the REST API addon integrates with the default endpoints from WordPress Core. Currently, all GET post and term routes are supported.

These include:

  • /wp/v2/posts
  • /wp/v2/pages
  • /wp/v2/media
  • /wp/v2/categories
  • /wp/v2/tags

And also all routes for custom post types and custom taxonomies on your website that have support for the REST API enabled.

The following fields will be included in the response of these routes:

aioseo_head

This field includes the raw SEO data that would normally be output by All in One SEO into the source code of your post/term as a text string.

If you have a headless WordPress website, you can output this data straight into the source code on the frontend of your installation.

aioseo_head_json

This field includes the same values of the aioseo_head data (see above), but in JSON format.

This allows you to easily filter the data before you output it into the source code or use it for another purpose.

Please note that this data does not include the HTML code for the meta tags that these values are used for, so you’ll need to construct these yourself.

aioseo_meta_data

This field includes the data that is stored into AIOSEO’s custom post and term tables in JSON format.

This data should be mainly used when you want to manipulate the existing data and then update it on your website.

Updating data

In order to update data via the REST API, you must authenticate yourself. If you are unsure how to do this, please read the WordPress REST API documentation.

The user you’ve authenticated with must also have any of the following capabilities in order to be able to update any AIOSEO data via the REST API:

  • aioseo_page_general_settings
  • aioseo_page_social_settings
  • aioseo_page_schema_settings
  • aioseo_page_advanced_settings

Once you’ve met these requirements, you can update data via a POST/PUT request by adding the property aioseo_meta_data in the body of the request.

Inside this property, you can specify any of the keys that are included in the aioseo_meta_data field (see above), along with the new value.

Below is an example of how this looks like:

{
	"aioseo_meta_data": {
		"title":"NEW TITLE",
		"description":"NEW DESCRIPTION"
	}
}

If you have any particular questions about the REST API, please feel free to reach out to our support team. We will be more than happy to help you.