Chris
Chris

Reputation: 769

How to get latest NuGet artifact version with JFrog Artifactory REST API, based on property?

Artifact management system is JFrog Artifactory Pro X.

According to REST API of JFrog in my Jenkins job with REST API I try to get latest artifact version of a specific package, in this case the id is "MyLib".

My NuGet package is stored here: https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg?properties=nuget.version, which results in following JSON response:

{
  "properties" : {
    "nuget.version" : [ "1.0.0" ]
  },
  "uri" : "https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg"
}

Also with following URL: https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg?properties=nuget.id I get valid JSON response:

{
  "properties" : {
    "nuget.id" : [ "MyLib" ]
  },
  "uri" : "https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg"
}

I tried with following URL https://artifactory.myserver.net/artifactory/api/versions/_any/_any?nuget.id=MyLib, but got

{
  "errors" : [ {
    "status" : 404,
    "message" : "Not Found"
  } ]
}

What is the correct URL to get the latest version, based on the property "nuget.id"?

Upvotes: 2

Views: 2680

Answers (1)

jroquelaure
jroquelaure

Reputation: 553

According to the doc artifactory/api/versions : Search for artifacts with the latest value in the "version" property. Only artifacts with a "version" property expressly defined will be returned.

In your case you do not have the "version" property set (I guess) but only "nuget.version" which is extracted metadata from the nuget packages during indexation.

Just set a "version" property on the package and the REST call will work.

You can automate this by using a user plugin in artifactory that will set the "version" property after the package has been written.

Another solution without the need of a user plugin would be to use the native nuget api for example with nuget v3 api :

https://artifactory.myserver.net/artifactory/api/nuget/v3/projectx-nuget/query?q= MyLib&prerelease=false

Will give you a json response with latest version (and also a list of other versions as mentionned in doc https://learn.microsoft.com/fr-fr/nuget/api/search-query-service-resource : "The metadata contained in the search result object is taken from the latest package version. Each item in the versions array is a JSON object " )

Upvotes: 3

Related Questions