0

I read the REST api again and again but couldn't figure out the exact syntax of how to search for an artifact in the artifactory using curl.

This is what I am doing:

result=$(curl -u ${ArtifactoryUsername}:${ArtifactoryAPIKey} -X GET "${artifactory_repo}/api/search/artifact?name=${generated_package_name}")
echo "${result}"

Here, artifactory_repo is

https://xxx.artifactory.xxx.com:443/artifactory/hyc-ca-container-helm-local

and hyc-ca-container-helm-local is my repo which I already appended on the end of my artifactory url

The file is there in the artifactory but I am getting the message file not found. I am sure the reason is that the syntax I am using is incorrect.

Can anyone guide me here?

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
Dam
  • 41
  • 1
  • 8

2 Answers2

1

You can use the Artifactory Query Language (AQL) along with the REST API and do the search.

Eldad Assis
  • 10,464
  • 11
  • 52
  • 78
1

If you are searching for an artifact within a given repository (using the artifact search API), you should use the following format:

GET /api/search/artifact?name=lib&repos=libs-release-local

For the code you have n your question, it should be:

result=$(curl -u ${ArtifactoryUsername}:${ArtifactoryAPIKey} -X GET "https://xxx.artifactory.xxx.com:443/artifactory/api/search/artifact?name=${generated_package_name}&repos=hyc-ca-container-helm-local")

Notice that the repository name (hyc-ca-container-helm-local) should be provided as a query parameter and not as part of the URL. You have placed it before the api context which lead to the 404 error.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57