All Products
Document Center

Demo code for obtaining a list of applications

Last Updated: Sep 09, 2021

Header file for completing basic configurations

The configurations that you specify in this header file will be used to implement the document push and document query features. The configurations include the AccessKey information, API endpoint, application name, drop-down suggestion name, and options.

// Import the header file.
use OpenSearch\Client\OpenSearchClient;

// Specify the AccessKey ID of your Alibaba Cloud account.
$accessKeyId = '<Your accessKeyId>';
// Specify the AccessKey secret of your Alibaba Cloud account.
$secret = '<Your secret>';
// Specify the endpoint of the OpenSearch API in your region. You can obtain the endpoint on the details page of the application in the OpenSearch console.
$endPoint = '<region endPoint>';
// Specify the application name.
$appName = '<app name>';
// Specify the drop-down suggestion name.
$suggestName = '<suggest name>';
// Enable the debugging mode.
$options = array('debug' => true);
// Create an OpenSearchClient object.
$client = new OpenSearchClient($accessKeyId, $secret, $endPoint, $options);

Obtain a list of applications that are managed within the current Alibaba Cloud account

The following demo code shows how to obtain a list of applications that are managed within the current Alibaba Cloud account.

// Import the header file.
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.
// Display debugging information.
echo $ret->traceInfo->tracer;