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');
  }
});

Edit Extracted Data Example

Disable Retry Flow and Handle Error

SmartExtract by default triggers a retry flow in case data extraction for a document fails. In case user provided some meta information incorrectly, this gives them a chance to re-fill the form and try extraction again. However, if you want to handle error within client application you may disable the retry flow. When the retry flow is disabled, the returned promise will be rejected in case of an error in data extraction

Styling and Customisations

SmartExtract provides various options so that you can style different elements on the SmartExtract component to match the look and feel of your application. Following are complete type definition for all the customisation options that you can provide:

ReactJS Integration

If you want to use SmartExtract with in your ReactJS application, you can wrap the SmartExtract API in a simple hook that you can use in your components:

Last updated