1

I use RAW format repository in my Nexus called myrepo. I upload files such as .tar.gz, zip, exe ...etc. In this repository I've many sub-folders and files and now I want to list all of the files with API.

I use this execution, generated by Nexus UI:

curl -X GET "http://localhost:8081/service/rest/v1/search?repository=myrepo&format=raw" -H  "accept: application/json"

The problem is that results are not full. The result are around 1000 lines of json, but there are another files which are missing from the results.

I've also try to filter by name:

curl -X GET "http://localhost:8081/service/rest/v1/search?q=update&repository=myrepo&format=raw" -H  "accept: application/json"

but is the same - The list is not complete.

My question is:

How can I list all of the components in this RAW repository?

airdata
  • 577
  • 1
  • 7
  • 23

2 Answers2

2

Use the integrated Pagination

https://help.sonatype.com/repomanager3/rest-and-integration-api/pagination

you GET the first page of result, then check for continuationToken

{
  "items" : [
    ...
  ],
  "continuationToken" : "88491cd1d185dd136f143f20c4e7d50c"
}

if it's not null there's more to GET simply adding:

&continuationToken=continuationToken

to your get, Groovy with JsonSlurper is great way to do it

1

I manage to do this with groovy script

In the script I get the token and pass it in loop like this:

import groovy.json.JsonSlurper

def nexusURL = "http://localhost:8081/service/rest/beta/search?repository=myrepo&format=raw"

// Make request to Nexus API and get continuationToken
def nexusAPIResponse = new URL(nexusURL).text;
def nexusAPISlurper = new JsonSlurper()
def nexusAPIResponseSlurper = nexusAPISlurper.parseText(nexusAPIResponse)
def continuationToken = nexusAPIResponseSlurper.continuationToken
  println "continuationToken: "+continuationToken
  println 'nexusAPIResponseSlurper: '+nexusAPIResponseSlurper.items.name.size()
  println "--------------------------------"

  try {
    while(continuationToken != 'null'){
    // Make request to Nexus API with continuationToken
    def nexusAPIResponseWithToken = new URL("${nexusURL}&continuationToken=${continuationToken}").text;
    def nexusAPISlurperWithToken = new JsonSlurper()
    def nexusAPIResponseSlurperWithToken = nexusAPISlurperWithToken.parseText(nexusAPIResponseWithToken)
      continuationToken = nexusAPIResponseSlurperWithToken.continuationToken
      nexusAPIResponseSlurperWithToken.items.name.each {
        println it
      }
    }
  }
  catch(IOException ex) {
    println "--------------------------------"
  }
airdata
  • 577
  • 1
  • 7
  • 23