@quadient/evolve-realtime-data-api-client
v0.0.11
Published
Library facilitating communication with the Digital Delivery Realtime Data API services.
Downloads
222
Keywords
Readme
Digital Delivery Realtime Data API Example
Overview
This example showcases how to parse a response from the Digital Delivery Realtime Data API.
Pre-requisities
- Digital Delivery application
- Realtime Data API enabled with the Native Storage DATA API type - see Documentation
- Digital Delivery endpoint: {host}/api/query/Messenger/BlobStorageDeltaApiQuery
Cursor Usage Example
// First time we call the API service, we need to provide a timestamp from which we want to list the data.
const date = new Date();
date.setHours(date.getHours() - 24);
const dataApiClient = new RealtimeDataApiClient(dataApiConnector);
const deltaData = await dataApiClient.getDelta(date);
// Save the cursor for the next API call.
const deltaData = await dataApiClient.getDelta(date);
await db.upsert("cursor", deltaData.cursor);
// For subsequent calls, we use the cursor saved from previous call.
const cursor = await db.get("cursor");
const dataApiClient = new RealtimeDataApiClient(dataApiConnector);
const deltaData = await dataApiClient.getDelta(cursor);
Response Parsing Example
const dataApiClient = new RealtimeDataApiClient(dataApiConnector);
const deltaData = await dataApiClient.getDelta(cursor);
for (const item of deltaData.deltaItems) {
if (item.deltaType === "EmailArchive" && item.customField.startsWith("myJobs")) {
console.log(item);
}
}