User Guides
Using the Public API
Paginating the API Requests
10min
pagination is a common technique used in apis to manage large datasets by splitting them into smaller, manageable chunks or pages this user guide explains how to use pagination with the api query parameters provided, including limit , offset , order , and dir in the following examples the endpoint /api/resource/ is used to explain the usage of pagination parameters, but this endpoint is not available please see the api documentation for endpoints supporting these parameters e g "get the organisations for which the current user is a member" pagination parameters 1\ limit description the limit parameter specifies the maximum number of entries to return in a single api response data type number default 1000 example get /api/resource?limit=10 in this example, the api will return a maximum of 10 entries in the response 2\ offset description the offset parameter determines the starting point within the list of entries from which results will be returned data type number default 0 example get /api/resource?offset=20 in this example, the api will skip the first 20 entries and return results starting from the 21st entry 3\ order description the order parameter allows you to specify the column by which you want to order the results for example, you can order by the created or updated column check the api specification for options data type string example allowed values created , updated default created example get /api/resource?order=created in this example, the api will order the results based on the created column 4\ dir description the dir parameter lets you specify the sort direction for ordered results you can choose either ascending ( asc ) or descending ( desc ) order data type string allowed values asc , desc default asc example get /api/resource?order=updated\&dir=desc in this example, the api will order the results by the updated column in descending order combining pagination parameters you can combine these pagination parameters to fine tune your api requests here's an example that demonstrates how to use all the parameters together get /api/resource?limit=20\&offset=40\&order=created\&dir=asc in this example limit=20 specifies that you want a maximum of 20 entries per page offset=40 skips the first 40 entries, starting from the 41st entry order=created dir=asc sorts the results in ascending order getting all the results to get all the data from a paginated api endpoint you need to loop until the number of returned items is less that the limit asked for for example const page size = 100; const results = \[]; while (true) { const searchparams = { limit page size, offset results length, order 'created', dir 'asc' }; // make the http request and wait for the response const response = await http get(`/api/resource?${new urlsearchparams(searchparams) tostring()}`); // add the page of data to the results array results push( response); // check if the response is the last if (response length < page size) { break; } }const maxresults = 1000 func getipsforscan(scanid string, apikey string) ( ipaddresses, error) { 	client = resty new() 	offset = 0 	var ips ipaddresses 	// get maxresults until we've got them all 	for { 	 // get the results 	 resp, err = client r() 	 setqueryparams(map\[string]string{ 	 "limit" fmt sprintf("%d", maxresults), // maximum number of entries to return 	 "offset" fmt sprintf("%d", offset), // offset into the list of entries to return 	 "order" "created", // column to order results by (\<created | last seen>) 	 "dir" "asc", // sort direction (\<asc | desc>) 	 }) 	 setheader("x hexiosec api key", apikey) 	 get(fmt sprintf("https //asm hexiosec com/api/v1/scan data/%s/ips", scanid)) 	 // check the err and response code 	 if err != nil { 	 return nil, fmt errorf("error calling api %q", err error()) 	 } else if resp statuscode() != httpstatusokay { 	 return nil, fmt errorf("error calling api got return code %d", resp statuscode()) 	 } 	 if err != nil { 	 return nil, err 	 } 	 // unpack the response body, decode the json 	 var newresults ipaddresses 	 err = json unmarshal(resp body(), \&newresults) 	 if err != nil { 	 return nil, fmt errorf("error unmarshalling json response %q", err error()) 	 } 	 // append them on 	 ips = append(ips, newresults ) 	 // check if we got them all 	 if len(newresults) < maxresults { 	 break 	 } 	 // increment the offset 	 offset += maxresults 	} 	return \&ips, nil } type ipaddresses \[]struct { 	id string `json "id"` 	ip string `json "ip"` 	dnssources \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "dns sources"` 	dnsptrs \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "dns ptrs"` 	services \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "services"` 	certificates \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "certificates"` 	cloudregions \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "cloud regions"` 	asns \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "asns"` 	entities \[]struct { 	 id string `json "id"` 	 name string `json "name"` 	} `json "entities"` 	riskcounts struct { 	 info int `json "info"` 	 low int `json "low"` 	 medium int `json "medium"` 	 high int `json "high"` 	 critical int `json "critical"` 	} `json "risk counts"` 	country string `json "country"` 	city string `json "city"` 	latitude float64 `json "latitude"` 	longitude float64 `json "longitude"` 	seed bool `json "seed"` 	created time time `json "created"` 	lastseen time time `json "last seen"` }