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 →

4 Replies to “Artifactory: API – List Artifacts in Repository – cURL”

  1. There is a syntax error in this aql file:
    items.find({
    “repo”:{“$match”:”web-*”}”
    })
    Should be:
    items.find({
    “repo”:{“$match”:”web-*”}
    })

    1. Thanks

  2. I was wondering how would one get only certain files in a given path.
    For example my.downloads/0.0.4 in the packages repo?
    {
    “repo” : “packages”,
    “path” : “my.downloads/0.0.4”,
    “name” : “mc”,
    “type” : “file”,
    “size” : 23490560,
    “created” : “2022-05-19T11:08:39.816+02:00”,
    “created_by” : “somebody”,
    “modified” : “2022-05-19T11:08:39.515+02:00”,
    “modified_by” : “somebody”,
    “updated” : “2022-05-19T11:08:39.819+02:00”
    }

  3. I worked it out :
    items.find({“repo”:”%s”},{“path”:{“$match”:”%s/%s*”}})

Leave a Reply