edit-icon download-icon

Use callable APIs

Last Updated: Feb 27, 2018

Alibaba Cloud C++ SDK provides callable APIs to meet your needs on flexibility. A callable API is called in the format of request action + Callable, such as describeInstancesCallable.

The following codes demonstrate how to call the callable API of DescribeInstances to obtain the detailed detained information of all ECS instances in the specified region.

Note: You must replace the values of your-region-id, your-access-key-id, and your-access-key-secret in the example.

  1. #include <iostream>
  2. #include <alibabacloud/core/AlibabaCloud.h>
  3. #include <alibabacloud/ecs/EcsClient.h>
  4. using namespace AlibabaCloud;
  5. using namespace AlibabaCloud::Ecs;
  6. int main(int argc, char** argv)
  7. {
  8. // Initialize the SDK
  9. AlibabaCloud::InitializeSdk();
  10. // Configure the ECS instance
  11. ClientConfiguration configuration("<your-region-id>");
  12. EcsClient client("<your-access-key-id>", "<your-access-key-secret>", configuration);
  13. // Create an API request and set parameters
  14. Model::DescribeInstancesRequest request;
  15. request.setPageSize(10);
  16. auto call = client.describeInstancesCallable(request);
  17. auto outcome = call.get();
  18. if (!outcome.isSuccess())
  19. {
  20. // Handle exceptions
  21. std::cout << outcome.error().errorCode() << std::endl;
  22. AlibabaCloud::ShutdownSdk();
  23. return -1;
  24. }
  25. std::cout << "totalCount: " << outcome.result().getTotalCount() << std::endl;
  26. // Close the SDK
  27. AlibabaCloud::ShutdownSdk();
  28. return 0;
  29. }
Thank you! We've received your feedback.