SmartExtractSimple API Examples
Data Extraction Example
import { SmartExtactSimple } from '@clik-ai/smart-extract';
const smex = new SmartExtractSimple();
// Instead of assigning to a global variable you'll need to persist
// the extracted data in a DB
let extractedData = null;
// SmartExtract needs the input file to be encoded as a Data URL.
// You may have your users select a file in browser and encode it as a Data URL
// or you may get the file as Data URL from an API
// See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
async function extractData(token) {
const { fileDataUrl, fileName } = await getFileData();
return smex.extractDocumentData({
session: {
mountNode: document.getElementById('smex-wrapper-div'),
sessionAuthToken: token,
// for multi-extraction
// multiple: true,
},
file: fileDataUrl,
fileName,
});
});
// Get auth token and start SmartExtract session
getAuthToken().then(async (token) => {
extractedData = await extractData(token);
if (extractedData !== null) {
console.log('Extracted data: ', extractedData);
} else {
console.log('User cancelled data extraction');
}
});