Background: The Artifactory supports the Get File Info API and the Artifactory Query Language to search artifacts in Artifactory. The REST API and AQL can search the artifacts and return the artifacts with detailed information, but can't search the Packages information in Artifactory.
If we want to get specific information about the Packages in the Artifactory, for example, the package version, package locations, download state of each package version, and so on, we can use GraphQL to search for the Packages in Artifactory and it can return more information about the Packages.
GraphQL: GraphQL is a query language for your API and a server-side runtime for executing queries using a type system you define for your data. The Artifactory supports GraphQL to search Metadata in the Artifactory and fetch package data stored in the metadata microservice. To get more, see GraphQL.
To use GraphQL to search metadata, it needs a scoped token for Artifactory and running the cURL request.
# curl example:
curl -H "Authorization: Bearer <Your Token>" -XPOST http://<server:port>/metadata/api/v1/query -d '{"query":"..." }'
How to use GraphQL to search Packages in the Artifactory: We can use GraphQL to search package data and it supports filtering queries by package name, package version, package type and so on. For more query parameters, we can refer to the GraphQL Filter Types and the Entities and Fields for response.
About the GraphQL filter and query for Packages, for example:
query {
packages(
# Filter fields to search Package
filter: {
name: "log4j", # Package name
packageTypeIn: [MAVEN], # Package Type
createdMin: "2019-12-25T00:00:01.000Z", # greater than or equal to the provided time
createdMax: "2019-12-25T00:00:02.000Z", # less than or equal to the provided time
...
latestVersion: "3*", # Match the latest version string
}
)
# Output fields of searched Package
{
edges {
node {
name # Package Name
packageType # Package Type
created # Create time for the Package
modified # Modified time for the Package
versionsCount # Version count for the Package
latestVersion # The latest version for the Package
......
# The licenses about the Package
licenses{
name # license name
source # license source
url # license URL
......
}
properties{
name # properties name
value # properties value
}
# More versions information of the Package
versions{
name
repos{
name # The repo name that the version location for the Package
type # The repo Type
}
stats{
downloadCount # version download count
}
}
......
}
}
}
}
For example 1: To search for a maven package with a name like log4j and return all versions, locations, and download status in Artifactory.
curl --location 'http://<server:port>/metadata/api/v1/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <Your Token>' \
--data '{
"query":"query
packages (
filter: {
name:\"log4j\",
packageTypeIn:[MAVEN]
}
)
{ edges
{
node
{
name
packageType
versionsCount
latestVersion
versions
{
name
repos{
name
type
}
stats{
downloadCount
}
}
}
}
}
"
}'
The search returns like this:
{
"data": {
"packages": {
"edges": [
{
"node": {
"name": "log4j",
"packageType": "maven",
"versionsCount": 1,
"latestVersion": "1.2.12",
"versions": [
{
"name": "1.2.12",
"repos": [
{
"name": "test_maven_local",
"type": "local"
},
{
"name": "test-maven-remote-cache",
"type": "remote"
},
{
"name": "test-2-maven-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
}
]
}
},
{
"node": {
"name": "log4j",
"packageType": "maven",
"versionsCount": 2,
"latestVersion": "2.17.2",
"versions": [
{
"name": "2.17.2",
"repos": [
{
"name": "test_maven_local",
"type": "local"
},
{
"name": "test-maven-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 1
}
},
{
"name": "2.13.3",
"repos": [
{
"name": "test_maven_local",
"type": "local"
},
{
"name": "test-maven-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
}
]
}
}
]
}
}
}
For example 2: To search for a docker or oci package with the name like busybox and return all versions, locations and download status in the Artifactory.
curl --location 'https://<server:port>/metadata/api/v1/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <Your Token>' \
--data '{
"query":"query
{
packages(
filter: {
name:\"*busybox*\",
packageTypeIn:[DOCKER OCI]
}
)
{
edges
{
node
{
name
packageType
versionsCount
latestVersion
versions
{
name
repos{
name
type
}
stats{
downloadCount
}
}
}
}
}
}
"
}'
The search returns like this:
{
"data": {
"packages": {
"edges": [
{
"node": {
"name": "busybox",
"packageType": "docker",
"versionsCount": 6,
"latestVersion": "v1.0",
"versions": [
{
"name": "sha256__aa755d1f0eea47f3b42c293fdeffcf252ec76c045eaa3900bd224c5413ff79b6",
"repos": [
{
"name": "4-docker-prod-local",
"type": "local"
}
],
"stats": {
"downloadCount": 3
}
},
{
"name": "sha256__a269ec0ecc52ab767b68554b5a407e9ff87c858cd88ec9286a187c39d1eff735",
"repos": [
{
"name": "4-docker-prod-local",
"type": "local"
}
],
"stats": {
"downloadCount": 3
}
},
{
"name": "sha256__5f577ed33dc18d221768d0944e08bd0750e864e48d863131a6694e3bed97f569",
"repos": [
{
"name": "app1-docker-prod-local",
"type": "local"
},
{
"name": "4-docker-local",
"type": "local"
}
],
"stats": {
"downloadCount": 3
}
},
{
"name": "1.33",
"repos": [
{
"name": "3-docker-prod-local",
"type": "local"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "v1.0",
"repos": [
{
"name": "1-docker-local",
"type": "local"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "latest",
"repos": [
{
"name": "2-docker-releases-local",
"type": "local"
}
],
"stats": {
"downloadCount": 3
}
}
]
}
},
{
"node": {
"name": "library/busybox",
"packageType": "docker",
"versionsCount": 7,
"latestVersion": "latest",
"versions": [
{
"name": "sha256__023917ec6a886d0e8e15f28fb543515a5fcd8d938edb091e8147db4efed388ee",
"repos": [
{
"name": "1-docker-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "sha256__2376a0c12759aa1214ba83e771ff252c7b1663216b192fbe5e0fb364e952f85c",
"repos": [
{
"name": "1-docker-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "sha256__67a8ef886e2ca4055f00e7cd13aedb9b24148c1451a6832d16fcc997a157eedc",
"repos": [
{
"name": "1-docker-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "sha256__51de9138b0cc394c813df84f334d638499333cac22edd05d0300b2c9a2dc80dd",
"repos": [
{
"name": "2-docker-hub-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "sha256__05a79c7279f71f86a2a0d05eb72fcb56ea36139150f0a75cd87e80a4272e4e39",
"repos": [
{
"name": "2-docker-hub-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "sha256__3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79",
"repos": [
{
"name": "1-docker-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 0
}
},
{
"name": "latest",
"repos": [
{
"name": "1-docker-hub-remote-cache",
"type": "remote"
},
{
"name": "2-docker-remote-cache",
"type": "remote"
}
],
"stats": {
"downloadCount": 5
}
}
]
}
}
]
}
}
}