|
/ Documentation /Developers Documentation/ Add Entries to the API Catalog surerank_pro_api_catalog_entries

Add Entries to the API Catalog surerank_pro_api_catalog_entries

Hook: surerank_pro_api_catalog_entries

Description: The surerank_pro_api_catalog_entries filter changes the list of APIs in the API catalog that SureRank Pro publishes at /.well-known/api-catalog. By default the catalog lists the WordPress REST API. The filter can add the REST API of another plugin, or remove an entry, so an AI agent finds every API of the site in one place.

Source: inc/modules/ai-readability/api-catalog.php (SureRank Pro)

Usage: Use this filter to add or remove APIs in the catalog. The filter receives one value, $entries, which is a list of entries, and it must return a list. Each entry is an array with an anchor (the address of the API) and a service-desc list (the description of the API). An entry can also carry a service-doc list that points to the documentation.

Note:

This filter is available in SureRank Pro, version 1.12.0 or later, and it needs the Publish an API Catalog switch to be on. See How to Publish Agent Discovery Files in SureRank.

Example: Add the REST API of Another Plugin

If you’re looking to list the REST API of another plugin in the catalog, add the code below. Replace my-plugin/v1 with the REST namespace of the plugin, the title with its name, and the documentation address with your own.

// Add the REST API of another plugin to the API catalog.
add_filter( 'surerank_pro_api_catalog_entries', 'my_api_catalog_entry' );

function my_api_catalog_entry( $entries ) {
    // $entries is the list of APIs already in the catalog. Add one more.
    $entries[] = array(
        // The address of the API.
        'anchor'       => rest_url( 'my-plugin/v1' ),

        // The description of the API. Every item needs an "href".
        'service-desc' => array(
            array(
                'href'  => rest_url( 'my-plugin/v1' ),
                'type'  => 'application/json',
                'title' => 'My Plugin REST API',
            ),
        ),

        // Optional: where the documentation of the API is.
        'service-doc'  => array(
            array(
                'href' => 'https://example.com/docs/my-plugin-api/',
                'type' => 'text/html',
            ),
        ),
    );

    // Always return the list.
    return $entries;
}

You can add the example code to your child theme’s functions.php file or use a plugin like Code Snippets to safely insert custom code. Using a code snippet plugin is recommended for easier management and to ensure the code remains active even if you switch themes.

Expected Outcome

After you add the code, open https://example.com/.well-known/api-catalog in a browser. Replace example.com with your domain. The catalog now lists the new entry after the WordPress REST API entry.

Notes

  • The filter must return a list. Return $entries at the end of the function.
  • SureRank passes each entry through as it is. The extra service-doc list in the example is shown in the catalog without changes.
  • The catalog is served as application/linkset+json.
  • SureRank does not change or remove the entries that the filter returns, so check the catalog in a browser after each change.
  • AI Ready Checks tests the catalog. Every entry in the list needs at least one link, and each link needs an href. An entry that has only an anchor makes the API Catalog row show a Warning that reads “Something else is answering at /.well-known/api-catalog.”
  • The AI catalog links to the API catalog as a whole. It does not list the entries added here one by one. To add an entry to the AI catalog, see Add Entries to the AI Catalog surerank_pro_ai_catalog_entries.

Related Docs

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top