To show all entries in responses, paged queries are often used for some API operations that may return a large number of entries. When you do not notice hidden entries, you assume that not all entries are returned.

Cause analysis

For example, after you call the DescribeImages operation to query available public images in the China (Hangzhou) region, the return value of TotalCount is 39, which indicates that a total of 39 entries are returned. By default, the 39 entries are displayed on 4 pages.

If you want to view all the entries on one page, set the PageSize request parameter to a value greater than 39. If you are using the SDK for Java to call the operation, you can set PageSize in the request to a value greater than 39 by using the setPageSize method to obtain all the entries of 39 images on one page.

The following table describes the PageSize and PageNumber parameters.

Parameter Type Required Description
PageNumber Integer No The number of the page to return. ECS API operations whose name prefix is Describe are used to query information. For more information, see List of operations by function.

Pages start from page 1.

Default value: 1.

PageSize Integer No The number of entries to return on each page.

Maximum value: 100.

Default value: 10.

Note The maximum value of PageSize is 100. If more than 100 entries are returned after an API operation is called, you can set PageNumber to a value starting from 1 (such as 1, 2, or 3) at a time and call the operation multiple times to obtain all the entries in the response. If you are using the SDK for Java, you can specify the number of pages to return by using setPageNumber().

Example of the default SDK for Java code

In this example, the DescribeImages operation is called to query images and the PageSize request parameter is set to 10. If the value of PageSize is not set in the SDK for Java code, null is returned when getPageSize is used. By default, the API server sets PageSize to 10. Sample code:

DescribeImagesRequest describe = new DescribeImagesRequest();
        //describe.setPageSize();//The default value of PageSize is 10.
        describe.setRegionId("cn-hangzhou");
        describe.setImageOwnerAlias("system");
        System.out.println("Value of PageSize in the request:"+describe.getPageSize());
        DescribeImagesResponse response
                = client.getAcsResponse(describe);

        System.out.println("Number of images:"+response.getTotalCount());
        System.out.println("Number of images in the response="+response.getImages().size());
            

Example of the custom SDK for Java code

In this example, the DescribeImages operation is called to query images and 39 entries are returned. You can set PageSize to 50 by using setPageSize to obtain all image entries at a time. Sample code:

DescribeImagesRequest describe = new DescribeImagesRequest();
        describe.setPageSize(50);// Use setPageSize to set PageSize to 50 in the request.
        describe.setRegionId("cn-hangzhou");
        describe.setImageOwnerAlias("system");
        System.out.println("Value of PageSize in the request:"+describe.getPageSize());
        DescribeImagesResponse response
                = client.getAcsResponse(describe);

        System.out.println("Number of images:"+response.getTotalCount());
        System.out.println("Number of images in the response="+response.getImages().size());