Enthusiast
Enthusiast

REST API pagination problem

Jump to solution

Hi,

Im using this REST command to get a list of all vcd users:

curl -i -k -H "Accept:application/*+xml;version=31.0" -H "x-vcloud-authorization:f9c49bfdghkjkfgd4ebf4d7e2d89c17b" -X GET https://my-vcd/api/query?type=adminUser

the problem is im getting only the first page.

<QueryResultRecords xmlns="http://www.vmware.com/vcloud/v1.5" xmlname="adminUser" page="1" pageSize="25" total="43" href="https://my-vcd/api/query?type=adminUser&page=1&pageSize=25&format=records">

    <Link rel="nextPage" href="https://my-vcd/api/query?type=adminUser&page=2&pageSize=25&format=records" type="application/vnd.vmware.vcloud.query.records+xml"/>

    <Link rel="lastPage" href="https://my-vcd/api/query?type=adminUser&page=2&pageSize=25&format=records" type="application/vnd.vmware.vcloud.query.records+xml"/>

    <Link rel="alternate" href="https://my-vcd/api/query?type=adminUser&page=1&pageSize=25&format=references" type="application/vnd.vmware.vcloud.query.references+xml"/>

this info is from the header.

as you can see I have total of 43 users spread into 2 pages.

I have read the REST manual and tried the following:

curl -i -k -H "Accept:application/*+xml;version=31.0" -H "x-vcloud-authorization:f9c49bfdghkjkfgd4ebf4d7e2d89c17b" -X GET https://my-vcd/api/query?type=adminUser&page=2

curl -i -k -H "Accept:application/*+xml;version=31.0" -H "x-vcloud-authorization:f9c49bfdghkjkfgd4ebf4d7e2d89c17b" -X GET https://my-vcd/api/query?type=adminUser&pageSize=128 (128 is the max entries number per page)

but I keep getting the first page..

I wish to get all 43 users in the same page.

any help ?

Tags (4)
1 Solution

Accepted Solutions
Expert
Expert

You must also put the request in quotation marks. The "&" character is otherwise interpreted by the shell (execute task in the background) and is no longer part of the request for curl. Therefore your request is always truncated at the "&" character and you always see the same page.

So the right thing would be:

curl -i -k -H "Accept:application/*+xml;version=31.0" -H "x-vcloud-authorization:f9c49bfdghkjkfgd4ebf4d7e2d89c17b" -X GET "https://my-vcd/api/query?type=adminUser&page=2"

--- Regards, Sebastian VCP6.5-DCV // VCP7-CMA // vSAN 2017 Specialist Please mark this answer as 'helpful' or 'correct' if you think your question has been answered correctly.

View solution in original post

1 Reply
Expert
Expert

You must also put the request in quotation marks. The "&" character is otherwise interpreted by the shell (execute task in the background) and is no longer part of the request for curl. Therefore your request is always truncated at the "&" character and you always see the same page.

So the right thing would be:

curl -i -k -H "Accept:application/*+xml;version=31.0" -H "x-vcloud-authorization:f9c49bfdghkjkfgd4ebf4d7e2d89c17b" -X GET "https://my-vcd/api/query?type=adminUser&page=2"

--- Regards, Sebastian VCP6.5-DCV // VCP7-CMA // vSAN 2017 Specialist Please mark this answer as 'helpful' or 'correct' if you think your question has been answered correctly.

View solution in original post