The server Public API offers a way to programmatically access and utilize the same functionalities available through the HTTP Public API within Livingdocs. You can find further information about the API, including its functions and arguments, by visiting the HTTP Public API reference.
This document provides a few examples demonstrating how to utilize the server Public API. For more detailed information, please reach out to your Customer Solutions contact.
Get Latest Publication
Related
API
const publicApi = liServer.features.api('li-public-api')
// get publication with documentId 53
const documentVersion = await publicApi.getLatestPublication({projectId: 12, documentId: 53})
Get Latest Publications
Related
API
const publicApi = liServer.features.api('li-public-api')
// get publications by ids
const documentVersions = await publicApi.getLatestPublications({
projectId: 12,
documentId: [53, 57]
})
The query allows the following entries:
projectId
, mandatory, the projectId (int) for which documents are searcheddocumentId
, filter by one, multiple or documentId ranges (Supported filters: id.gte, id.gt, id.lte, id.lt)contentTypes
, array of contentType handles (string) to filter for (OR concatenated)fields
, array of fields (string) to include for results (see Fields)includeReferences
, default: false, addsreferences
to FieldspublishedAt
, filter by publish date range. (Supported filters: publishedAt.gte, publishedAt.gt, publishedAt.lte, publishedAt.lt)reverse
, order publications in ascending order instead of the default descending order. This is useful if you want to paginate using a time based filter with publishedAt.limit
, integer of how many results to get, default 10after
, offset into the filter. Useful when getting more than 100 results (pagination). Max. 10000. Prefer range based filters like documentId.get or publishedAt.gte.
Examples
// get multiple documents by id
const documentVersions = await publicApi.getLatestPublications({
projectId: 12,
documentId: [53, 57]
})
// get documents by id range e.g. for exports
const documentVersions = await publicApi.getLatestPublications({
projectId: 12,
documentId: {gt: 0, lte: 100}
})
// retrieve all publications since a specific timestamp
const documentVersions = await publicApi.getLatestPublications({
projectId: 12,
publishedAt: {gte: '2021-05-01T00:00:00.000Z'}
})
Search Publications
Related
API
const publicApi = liServer.features.api('li-public-api')
const documentVersions = await publicApi.searchPublications({
projectId: 12,
contentTypes: ['regular']
})
The query allows the following entries:
projectId
, mandatory, the projectId (int) for which documents are searchedsearchTerm
, string used for full-text searchcontentTypes
, array of contentType handles (string) to filter for (OR concatenated)categories
, array of category ids (string) to filter for (OR concatenated)languages
, array of language handles (string) to filter for (OR concatenated)languageGroupId
, string of a single language groupfilters
, array or object (see Filters)sort
, array of fields (string or object) to sort results by (see Sort)fields
, array of fields (string) to include for results (see Fields)limit
, integer of how many results to get, default 10offset
, integer from which position to count results, useful for pagination, default 0. Max. 10000.
Examples
const publicApi = liServer.features.api('li-public-api')
// search for Regular articles with title 'My Article'
const documentVersions = await publicApi.searchPublications({
projectId: 12,
contentTypes: ['regular'],
filters: {
key: 'metadata.title', term: 'My Article'
}
})
// get documents by id range
const documentVersions = await publicApi.searchPublications({
projectId: 12,
contentTypes: ['regular'],
filters: {
key: 'documentId', range: {gt: 0, lte: 100}
}
})
Command API
Related
API
const publicApi = liServer.features.api('li-public-api')
// add paragraph after the first component
await publicApi.executeDocumentCommands({
documentId: documentVersion.id,
projectId: documentVersion.projectId,
commands: [
{
// Inserts a new component into the document content.
operation: 'insertComponent',
componentId: 'doc-custom-123456',
componentName: 'p',
content: {
text: 'I automatically added a new paragraph.'
},
position: {
previousComponentId: documentVersion.content[0].id
}
}
]
})
The function allows the following parameters:
projectId
, mandatory, the projectId (int) for which documents are searcheddocumentId
, mandatory, document to updateconditions
, mandatory, an array of commands to execute.userId
, optional, user which updated the documentversion
optional, current document version. When set on update the version is checked.preconditions
, optional, If a precondition assertion fails, no commands are executed
Please check HTTP Public API - Document Command API for a more detailled description of how to apply conditions
, version
, preconditions
.