I'm sending get requests to this api
to get the list of vulnerabilities for a container image, however the full list is separated in pages, and modifying the request by adding a pageToken
parameter is needed to obtain anything besides the first page. I can't figure out how to add that pageToken. I've tried adding it as a header and adding it to the url (?pageToken=
or &pageToken=
and different encoding combinations), but they didn't work. I can't find documentation on how to do this with curl.
Examples of requests I've tried are:
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://containeranalysis.googleapis.com/v1beta1/projects/my_project/occurrences?filter=kind%3D%22VULNERABILITY%22%20AND%20resourceUrl%3D%22https%3A//us.gcr.io/my_project/tabulate%40sha256%3Ahash%22%26PageToken%3D%22token_number%22
or
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" https://containeranalysis.googleapis.com/v1beta1/projects/my_project/occurrences?filter=kind%3D%22VULNERABILITY%22%20AND%20resourceUrl%3D%22https%3A//us.gcr.io/my_project/tabulate%40sha256%3Ahash%22?PageToken=%22token_number%22
for these two I get
{
"error": {
"code": 500,
"message": "Unknown Error.",
"status": "UNKNOWN"
}
}
I got this to work using python's request library. for example this works well:
url = 'https://containeranalysis.googleapis.com/v1/projects/{}/occurrences'
parameter = '?pageSize=1&pageToken={}'
response = requests.get(
url.format(project_ID) + parameter.format(page_token),
headers={"Authorization": f"Bearer {auth_token}"})
where page_token
is whatever token has been returned previously by the API