Skip to main content

Quick Start

Choose your integration path:

Backend Integration

Get upload tokens and call verify-pot-sizes

Frontend Integration

Upload files with Uppy

Backend Examples

Get Upload Token

async function getUploadToken(merchantId, platformApiKey) {
  const response = await fetch('https://api.superseeded.ai/v1/auth/delegate-upload', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${platformApiKey}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ merchant_id: merchantId })
  });
  
  if (!response.ok) {
    throw new Error(`Failed to get upload token: ${response.statusText}`);
  }
  
  const data = await response.json();
  return data.token;
}

Call Verify Pot Sizes

After a successful upload, call the verify-pot-sizes endpoint with the delegation token and file URL to process the file and retrieve enriched data.
async function validatePotSizes(delegationToken, fileUrl) {
  const response = await fetch('https://api.superseeded.ai/v1/verify/pot-sizes', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${delegationToken}`, // Same token used for upload
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ file_url: fileUrl })
  });
  
  if (!response.ok) {
    throw new Error(`Failed to resolve specs: ${response.statusText}`);
  }
  
  const data = await response.json();
  
  console.log(`Processed ${data.usage.rows_processed} rows`);
  console.log(`Billable: ${data.usage.is_billable}`);
  
  // Save enriched_data to your database
  await saveEnrichedData(data.enriched_data);
  
  return data;
}

Frontend Examples

Upload with Uppy (Framework-Agnostic)

import Uppy from '@uppy/core'
import Tus from '@uppy/tus'

function createUppyUploader(uploadToken, onUploadComplete) {
  const uppy = new Uppy({
    autoProceed: true,
    restrictions: {
      allowedFileTypes: ['.csv', '.xlsx', '.xls', '.json']
    }
  });
  
  uppy.use(Tus, {
    endpoint: 'https://secure.superseeded.ai/files/',
    headers: {
      'Authorization': `Bearer ${uploadToken}`
    },
    chunkSize: 5 * 1024 * 1024, // 5MB
    retryDelays: [0, 1000, 3000, 5000]
  });
  
  uppy.on('complete', (result) => {
    onUploadComplete(result.successful[0]);
  });
  
  return uppy;
}

Complete Flow

Here’s the complete end-to-end integration:
async function completeUploadFlow(merchantId, file) {
  // 1. Get delegation token from your backend
  const token = await fetch('/api/get-upload-token', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ merchant_id: merchantId })
  }).then(r => r.json()).then(d => d.token);
  
  // 2. Upload file with Uppy
  const uppy = new Uppy({ autoProceed: true })
    .use(Tus, {
      endpoint: 'https://secure.superseeded.ai/files/',
      headers: { 'Authorization': `Bearer ${token}` }
    });
  
  uppy.addFile(file);
  const uploadResult = await uppy.upload();
  
  // 3. Get the file URL from the upload result
  const fileUrl = uploadResult.successful[0].uploadURL;
  
  // 4. Call validate-pot-sizes with the same delegation token and file URL
  const response = await fetch('https://api.superseeded.ai/v1/verify/pot-sizes', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`, // Same token used for upload
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ file_url: fileUrl })
  });
  
  const enrichedData = await response.json();
  
  console.log('Processing complete:', enrichedData);
  console.log(`Rows processed: ${enrichedData.usage.rows_processed}`);
  
  return enrichedData;
}

All Examples

For the complete set of examples, see the examples repository.