Getting Latest Azure DevOps Artifact Feed Package Version

The following Python script can be used to get the latest package version from a feed using Azure DevOps REST API’s. For the token, you need to generate a PAT token that at least has permissions to Packaging / Artifacts.

import requests
import base64
import json

def get_latest_package_version(organization, project, feed_name, token):
    token = str(base64.b64encode(bytes(':'+token, 'ascii')), 'ascii')
    headers = {'Authorization': 'Basic ' + token}

    feed = requests.get(f"{organization}/{project}/_apis/packaging/Feeds/{feed_name}?api-version=6.0-preview.1", headers=headers)
    feed_id = json.loads(feed.text)["id"]
    package = requests.get(f"{organization}/{project}/_apis/packaging/Feeds/{feed_id}/packages?api-version=6.0-preview.1", headers=headers)
    package_version = json.loads(package.text)["value"][0]["versions"][0]["version"]

    return package_version

organization = "my-org"
project = "my-project"
feed_name = "my-feed"
token = "*********************************************"

version = get_latest_package_version(organization, project, feed_name, token)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: