Artifactory: API – List Artifacts in Repository – cURL

Artifactory has a REST API and an AQL (Artifactory Query Language) that can be used to get a list of all artifacts in a repository from the command line.

In this note i will show how to list artifacts in a repository in Artifactory through the REST API using cURL and how to get the top 10 largest artifacts in a repository.

Cool Tip: Default password and how to access REST API in Artifactory! Read more →

Artifactory API to List Artifacts in Repository

List all artifacts in a repository:

$ curl -sSf -u "<USERNAME>:<PASSWORD>" \
       -H "content-type: text/plain" \
       -X POST \
       'http(s)://<ARTIFACTORY_URL>/api/search/aql' \
       -d 'items.find({"repo":"<REPO>"})'

This API call returns the repo, path, name, type, size and the timestamps created, created_by, modified, modified_by, updated of the each artifact in a repository.

In case of more complex queries to the Artifactory’s REST API it is easier to write them in a text file and pass to the curl command with -d @fileName.aql:

$ curl -sSf -u "<USERNAME>:<PASSWORD>" \
       -H "content-type: text/plain" \
       -X POST \
       'http(s)://<ARTIFACTORY_URL>/api/search/aql' \
       -d @fileName.aql

The contents of the fileName.aql:

items.find({
  "repo":"<REPO>"
})

List artifacts in the Artifactory repositories starting with web-*:

items.find({
  "repo":{"$match":"web-*"}"
})

List artifacts in the Artifactory repositories starting with web-* or db-*:

items.find({
  "$or":[{
    "repo":{"$match":"web-*"}",
    "repo":{"$match":"db-*"}"
  }]
})

Display the name, repo, path and size of the top 10 largest artifacts in a repository:

items.find({
  "repo":"<REPO>"
}).include("name","repo","path","size")
  .sort({"$desc": ["size"]})
  .limit(10)

Cool Tip: List repositories in Artifactory using cURL! Read more →