How do i get from API the id of custom image
I have created a custom image, iwould like to use through the API to create new linodes but the curl command i found in the get started documentation curl https://api.linode.com/v4/images/ | json_pp
do not seems to retrieve it, or i missed it ?
1 Reply
Curling that URL without authentication will list only public images. To list private and public images, our documentationexplains that you need to auth the token to the API Call like this:
curl -H "Authorization: Bearer $TOKEN" \
https://api.linode.com/v4/images
If you haven't already, you can follow this guide for creating an API token. Make sure it has proper permissions to view your private images and then set it as the $TOKEN
environment variable. (You can just copy and paste the token itself where it says $TOKEN if you want.)
To filter out any public images and just return your own, you can read about using X-filters. I played around with this for a while and figured out the syntax to get a readable list of just my own images:
curl -H "Authorization: Bearer $TOKEN" \
-H 'X-Filter: { "is_public": false }' \
https://api.linode.com/v4/images | json_pp
While it took me a while to get the exact right syntax for the API, if you want something more user friendly, I strongly recommend using the Linode CLI, which took about 30 seconds to figure out. It's a wrapper for our API and it's got a great help function. I sometimes run commands with the CLI and compare the response with API commands to see if I'm getting the correct output.
I found the basic command for listing images with CLI from our API documentation here:
linode-cli images list
From there, I ran the command with the --help
flag and got this:
linode-cli images list --help
linode-cli images list
Images List
API Documentation: https://www.linode.com/docs/api/images/#images-list
You may filter results with:
--label
--deprecated
--is_public
--size
--type
--vendor
--status
Additionally, you may order results using --order-by and --order.
The syntax for the CLI is usually pretty intuitive, so I ran this and it worked and the output was in a nice, neat table that's more readable than API output:
linode-cli images list --is_public=false
This does take a bit of time to set up but is easy to use when you run commands, whereas the API requires less work up front and more work each time you use it. Depending on your use case, if the CLI seems like something you'd like to try, you can check out our guide to getting started with the Linode CLI.