All Products
Search
Document Center

OpenSearch:Query the application list

Last Updated:Mar 18, 2026

This topic describes how to use the PHP SDK to query all applications under your Alibaba Cloud account.

Configure environment variables

Configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.

Important
  • The AccessKey pair of an Alibaba Cloud account can be used to access all API operations. We recommend that you use a Resource Access Management (RAM) user to call API operations or perform routine O&M. For information about how to use a RAM user, see Create a RAM user.

  • For information about how to create an AccessKey pair, see Create an AccessKey pair.

  • If you use the AccessKey pair of a RAM user, make sure that the required permissions are granted to the AliyunServiceRoleForOpenSearch role by using your Alibaba Cloud account. For more information, see AliyunServiceRoleForOpenSearch and Access authorization rules.

  • We recommend that you do not include your AccessKey pair in materials that are easily accessible to others, such as the project code. Otherwise, your AccessKey pair may be leaked and resources in your account become insecure.

  • Linux and macOS

    Run the following commands. Replace <access_key_id> and <access_key_secret> with the AccessKey ID and AccessKey secret of the RAM user that you use.

    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> 
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  • Windows

    1. Create an environment variable file, add the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables to the file, and then set the environment variables to your AccessKey ID and AccessKey secret.

    2. Restart Windows for the AccessKey pair to take effect.

Create a header file that contains configurations

The Config file contains important parameters that are required for querying and pushing documents. These parameters include the AccessKey, host, application name, drop-down suggestion name, and options.

<?php
// Import the header file.
require_once("../OpenSearch/Autoloader/Autoloader.php");
use OpenSearch\Client\OpenSearchClient;

// User identity information.
// Read the AccessKey ID and AccessKey secret from environment variables.
// Before you run the sample code, you must configure environment variables. For more information, see the "Configure environment variables" section.
// Replace this with your AccessKey ID.
$accessKeyId = getenv('ALIBABA_CLOUD_ACCESS_KEY_ID');
// Replace this with your AccessKey secret.
$secret = getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
// Replace this with the API endpoint in your region. You can find the endpoint on the Basic Information page of your application in the console.
$endPoint = '<region endPoint>';
// Replace this with your application name.
$appName = '<app name>';
// Replace this with the name of your drop-down suggestion model.
$suggestName = '<suggest name>';
// Enable the debug mode.
$options = array('debug' => true);
// Create an OpenSearchClient object.
$client = new OpenSearchClient($accessKeyId, $secret, $endPoint, $options);

Obtain a list of applications within the current Alibaba Cloud account

The following retrieval query returns all applications in the current account.

<?php
// Import the header file.
require_once("Config.inc.php");
use OpenSearch\Client\AppClient;
use OpenSearch\Generated\Common\Pageable;

// Create a Pageable object.
$pageable = new Pageable(array('page' => 1, 'size' => 10));
// Create an AppClient object.
$appClient = new AppClient($client);
// Run the query and return a list of applications.
$ret = $appClient->listAll($pageable);
// Display the list of applications.
print_r($ret);
// Display debugging information.
echo $ret->traceInfo->tracer;