Proper method to programmically fetch specific snap's version info

This is, for example, used in an override-pull scriptlet to query the building snap’s latest version on the Store, previously I parsed the snap info command’s output however it broke recently due to the text change.

I originally want to use Snapstore Devices API, however, it seems that the Snapd REST API more proper with the case.

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

I eventually used the Store API(reference), which don’t have the Snapd dependency.