Skip to main content
Version: v3

Environment Variables

This guide expands on server-side and client-side environment variables when embedding Flatfile in your product.


Overview

Flatfile provides two different ways for dynamically making some data available in your Data Hooks® environment during an import session.

Server side

From the server side, you can add an env field to your token payload. This field should contain all the data that you want to make available in your Data Hooks env.

const express = require("express");
const app = express();
const jwt = require("jsonwebtoken");

// This is a public Embed ID and a private key.
// Private key should be used to sign a JWT.
const EMBED_ID = "YOUR_EMBED_ID";
const PRIVATE_KEY = "YOUR_PRIVATE_KEY";

app.use(express.static("public"));
app.use(express.json());

app.post("/auth-flatfile", async (req, res) => {
const token = jwt.sign(
{
embed: EMBED_ID,
user: {
/** YOUR USER INFO HERE */
},
org: {
/** YOUR ORG INFO HERE */
},
// Here you can add whatever you want to send to your Data Hooks
env: {
foo: "Foo",
bar: "Bar",
},
},
PRIVATE_KEY,
);

res.send({ token });
});

app.listen(4242, () => console.log("Node server listening on port 4242!"));

Client side

There is also a way to send data to your Data Hooks env from the client side while an import session is running.

Flatfile.requestDataFromUser({
onInit: ({ meta, session }) => {
session.updateEnvironment({ foo: "Foo", bar: "Bar" });
},
});