List all possible dc:subjects values

Hi

I am trying to retrieve all possible values for subjects trough REST API (even if the subject is not used in any document)

Here is the POST request that I am sending to URL

http://localhost:8080/nuxeo/site/automation/Document.Query

HTTP headers:


X-NXDocumentProperties  * 
Accept: application/json+nxentity 
Content-type: application/json+nxrequest; charset=UTF-8 

POST body to


{"params":{"query":"SELECT DISTINCT dc:subjects/*1 FROM Document "},"context":{}} 

The problem is that I am receiving an empty result like:


{"entity-type":"documents","entries":[]} 

What I am doing wrong? (I do have some documents with assigned subjects). I guess even if I manage to run the query, it will return the assigned subjects (to any of the documents).

How can I return all the subjects, even if they are not assigned?

Thanks,

1 votes

1 answers

2893 views

ANSWER



Hi,

To retrieve all the possible subjects values, you need to use the Directory.Entries operation:

http://localhost:8080/nuxeo/site/automation/Directory.Entries

POST body to

{"params":{"directoryName":"topic"}}

This will return a JSON array like this:

[ { "id" : "art",
    "label" : "label.directories.topic.art",
    "obsolete" : 0,
    "ordering" : 10000000
  },
  { "id" : "human sciences",
    "label" : "label.directories.topic.humanscience",
    "obsolete" : 0,
    "ordering" : 10000000
  },
  { "id" : "society",
    "label" : "label.directories.topic.society",
    "obsolete" : 0,
    "ordering" : 10000000
  },
  { "id" : "daily life",
    "label" : "label.directories.topic.dailylife",
    "obsolete" : 0,
    "ordering" : 10000000
  },
  { "id" : "technology",
    "label" : "label.directories.topic.technology",
    "obsolete" : 0,
    "ordering" : 10000000
  }
]

This returns the first level topics. Change the directoryName to subtopic to get all the level2 topics.

2 votes