Hi, A GET request to “https://api.digitalocean.com/v2/sizes” should return a list of the available sizes. But when i try with
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer ****" "https://api.digitalocean.com/v2/sizes" | jq ".sizes[] | .slug"
I get
I have tried to resize a machine to a not-listed-above “c-16” size and its works! So my question is, why it is missing from the list returned by “/v2/sizes” ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
List responses from the DigitalOcean API are paginated. By default, only 20 items are listed in the first page. For example, this will return 20:
curl -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
"https://api.digitalocean.com/v2/sizes" | \
jq ".sizes[] | .slug" | wc -l
If we made this query without the jq
filter, we would see the response contains:
"links": {
"pages": {
"last": "https://api.digitalocean.com/v2/sizes?page=2",
"next": "https://api.digitalocean.com/v2/sizes?page=2"
}
},
"meta": {
"total": 29
}
This indicates that there are additional results that can be accessed on the next page by appending the page=2
query parameter to the request.
If you want to access more than 20 results per page, you can adjust this using the per_page
query parameter. The maximum number of results in a page is 200. So adjusting our request to use per_page=200
:
curl -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $DO_TOKEN" \
"https://api.digitalocean.com/v2/sizes?per_page=200" | \
jq ".sizes[] | .slug" | wc -l
we get 29 results. Also, the links
section of the response will be empty indicating that there are no additional pages.
Unfortunately, the API lists only sizes that are unlocked to you. I think the default is limited to sizes up to 100 USD/month. In the console, you can request to unlock larger sizes. It would be great if the API would list all sizes with an “unlocked” flag, instead, but this is not the case.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.