How to filter API list based on the input attribute for subscription?

When we click on new subscription button,instead of getting all the public API's we are looking to get the list of API's based on input attribute.

can you help us on how to find the hook and how to achieve.

please share the sample query/code for this if possible.

Thanks in advance.

0 3 120
3 REPLIES 3

You can do this by implementing hook_apiproduct_list_alter(). Here's the example from devconnect_developer_apps.api.php. What attribute are you planning to use?

/**
 * Alter the list of available API Products.
 *
 * @param Drupal\devconnect_developer_apps\ApiProductEntity[] $public_api_products
 *   An array of viewable ApiProductEntities keyed by name.
 * @param stdClass $account
 *   The user account associated with the app for which these products are
 *   displayed.
 * @param Drupal\devconnect_developer_apps\ApiProductEntity[] $private_api_products
 *   An array of non-public ApiProductEntities keyed by name, if any.
 */
function hook_apiproduct_list_alter(array &$public_api_products, $account = NULL, $private_api_products = array()) {
  // Give user 1 access to all private API Products.
  if ($account->uid == 1) {
    $public_api_products = array_merge($public_api_products, $private_api_products);
  }
}

Thanks for your response Karl.

Product will be tagged with this attribute "group-name" .

attributekey :: group-name

attributevalue :: XXXXX

when we click on "New Subscription", we need to filter the apiproducts based on the attribute (group-name). could you please suggest the solution?

This module might help as an example.