Connect Studio to Code
Last updated
Last updated
This documentation provides a detailed guide on how to use the Studio CLI and API for managing design tokens efficiently.
Navigate to Studio:
Open the Studio application.
Go to your organization dashboard.
Click the SDK and CLI button.
Review the SDK Documentation:
This contains the Studio Software Development Kit (SDK) and CLI instructions.
It might seem overwhelming, but the focus is on pulling your tokens into your local file system via the CLI.
Creating an API Key
Generate a Key:
Go to Personal Settings in Studio.
Select API Keys (below "Edit Profile").
Create a new API key (e.g., "Test Key").
Copy and Store the Key:
Copy the key string and store it securely (e.g., in a password manager or vault).
You won’t be able to view the key again after closing the window.
The API operates on a GraphQL interface. You can use tools like Postman, Curl, or the Apollo Sandbox to interact with it.
Access the Apollo Sandbox:
Configuring the Authorization Header:
In Apollo Sandbox:
Navigate to Settings > Connection Settings.
Click on Edit on the Connection settings. A modal will open.
In the Shared headers section, select "Authorization header" in the header key input. In the value input: Bearer <API_KEY>
(replace <API_KEY>
with your API key). Click Save.
View the available queries:
Run a Query:
Use the query editor in Apollo Sandbox to explore data (e.g., list all projects).
Example query - List of all projects in an Organization:
Click on "projects(...): PaginatedProjects!". The details will be filled in the Operation and Variables section.
Add "data: [Project!]!. This step is done because the Projects list is a paginated response.
Add "name" to get the name of the project and "oragnizationId" to specify the organisation.
A query would be generated in the Operations panel.
In the "Variables" section, we need to add the organisation id. To get the organisation ID, Navigate to your organization in Studio. Copy the Organization ID from the URL (after /org/
).
Return to the Apollo Sandbox, enter the organisation id in the "Variables section".
Run the query, the list of projects with the project name and the organisation id will be displayed in the right panel.
Set Up a Request:
Create a new POST request in Postman.
Use the same endpoint as Apollo Sandbox.
Add Authorization:
In the Authorization tab, select Bearer Token.
Paste your API key into the token field.
Check the Headers:
The headers will show a predefined Authorisation.
Define the Body:
The single line query will look like this:
Provide necessary variables (e.g., organization ID
) in the payload. The final query will look something like this:
Send the Request:
Execute the request by clicking on "Send" to receive JSON responses similar to the Apollo Sandbox.
Install the CLI:
Open the project that you want to connect Studio with.
Run npm install @tokens-studio/sdk
.
If you don’t have a package.json
, initialize it first with npm init
.
Ensure that the node.js version installed is v.22 or above.
Run the CLI:
Use the --help
flag to view available commands:
This will list all the available options
Set Up the CLI:
Run the setup
command:
Enter your API key when prompted. You can skip this step by Automating the CLI.
Select the desired organization and project.
The selected settings will be saved in the .tokensstudio.json
config file.
Pull Tokens:
Specify the folder to pull tokens into (relative to the config file). This can be done in the .tokensstudio.json
config file as output
.
Use the pull
command:
This will pull all the tokens in your project into the output specified in your config (.tokensstudio.json) file.
Automate the CLI:
Pass the API key as an environment variable for automation. This will ensure that the API key is not prompted for everytime.
Current Features:
Pull token sets into local files.
Simplify organization and project selection.
Planned Features:
Watch Mode: Automatically sync changes from Studio to local files.
Release Artifacts: Pull releases directly instead of token sets.
Secure API Key Storage:
Use a password manager or secure vault.
Avoid storing keys in plain text.
Automation:
Use environment variables to prevent manual prompts in CI pipelines.
Explore API Schema:
Use Apollo Sandbox for schema introspection before creating complex queries.
Open the GraphQL endpoint
The query section will show the available queries as can be seen in the .
Go to the Body tab. Select the "raw" option. In the input enter the "operationName" and "variables" as we have defined in the .
Use the "query" in the "Operation" section of Apollo Sandbox and convert it into a single-line string. You can use this to convert the query from multi-line to single-line.
This documentation provides an overview of using Studio’s API and CLI effectively. For further assistance, refer to the official .