Proper method to programmically fetch specific snap's version info

Well for snap versions, talking to snapd will in effect just end up talking to the store, so it’s really a question of which API is easier to talk to. IMHO, the snapd REST API is slightly easier but that’s really only cause I work on it and I don’t work on the store API :wink:

Something like this seems like it would work for you:

$ curl -s --unix-socket /run/snapd.socket http://localhost/v2/find?name=snapd | jq -r '.result | .[0] | .channels | ."latest/stable" | .version'
2.46.1

You could specify a specific channel other than latest/stable, etc. and just change the name parameter to the name of the snap you actually want

3 Likes