Hi,
I have a requirement where I need to pull all the entries (published & draft) from contentful and store the meta data for those entries in our DB for reporting/analytics purpose.
I see drawbacks in both CMA & CDA.
CDA: Its only pulling the PUBLISHED entries for a given ContentType. Not pulling the DRAFT entries for that contentType.
final CDAClient cdaClient = CDAClient.builder()
.setSpace(smSpaceId)
.setEnvironment(appActiveEnv)
.setToken(cdaAccessToken)
.build();
// Get the amount of Entries, without fetching the actual content
final int totalNumOfEntries =
cdaClient
.fetch(CDAEntry.class)
.withContentType(topicPageContentTypeId)
.limit(0)
.all()
.total();
log.info("Total CDAEntries :: {}", totalNumOfEntries);
try {
// create storage for the Entries
final List<CDAResource> resources = new ArrayList<CDAResource>(totalNumOfEntries);
// use page size, based on usecase
final int PAGE_SIZE = 10;
// loop through all pages and store results
for(int page = 0; page * PAGE_SIZE < totalNumOfEntries; ++page) {
final CDAArray currentPagedItems = cdaClient
.fetch(CDAEntry.class)
.withContentType(topicPageContentTypeId)
//.select("sys.id")
.skip(page * PAGE_SIZE)
.limit(PAGE_SIZE)
//.orderBy("sys.createdAt")
.all();
// add to current list of Entries
resources.addAll(currentPagedItems.items());
}
CMA : I don’t see any API where I can pull entries for a given ContentType. Because I see CMA API is pull both (published & draft) the entries but it does not have a filter based on the contentType.
final CMAClient client =
new CMAClient
.Builder()
.setAccessToken(cmaAccessToken)
.setSpaceId(smSpaceId)
.setEnvironmentId(appActiveEnv)
.build();
final CMAArray<CMAEntry> cmaArray = client
.entries()
.fetchAll();
Can someone help me here pointing to the right API which I can use to pull both PUBLISHED & DRAFT entries based on the contentType.
Thanks,
Deba