All Collections
Versions 3.0 and 2.0
Implement
Workspaces
Saving Variable Data in a Workspace Environment using GraphQL
Saving Variable Data in a Workspace Environment using GraphQL
Elisa Dinsmore avatar
Written by Elisa Dinsmore
Updated over a week ago

This article is for Flatfile's Workspaces. If you'd like to check out the latest version of the Flatfile Data Exchange Platform, click here!

Using Flatfile's GraphQL API, you may send data to a Workspace using the environment (env) variable, which is then accessible by a Data Hook®. This can be used, for example, to send authentication tokens that allow Flatfile Data Hooks to access an external API, or to dynamically set values that should be unique for a given customer or workspace.

The environment variable contains one or more key/value pairs that you can set.

If the following JSON were sent through GraphQL, it would create and store values for 3 keys in the environment variable: *mytoken*, *foo*, and *foo2*.

{
    mytoken: "ABCD1234",
    foo: "bar",
    foo2: true
}

You could then place that JSON in a variable (in this case, `env`), and then pass that variable, along with the Flatfile workspace ID that you want to update, to the following GraphQL mutation in your code:

mutationUpdateWorkspaceEnv($workspaceId: UUID!, $env: JSON!) {
updateWorkspaceEnvironment(workspaceId: $workspaceId, env: $enc) {
success
 }
}

After you have added data to the environment, you can access the key-value pairs using a Data Hook that references session.env.

For example, if you included a value for a variable named “mytoken” in env, your env key-value pair would look like mytoken: "anystring", and you could access the mytoken value using a Data Hook referencing session.env.mytoken.

Data passed into the environment variables like this will also be returned in Webhooks, and can be used to sign a webhook if need be.

Did this answer your question?