Getting Started
It’s pretty easy to set up the Contentstack Bridge.
Let’s walk through the steps that are needed to set it up.
Installation steps
Getting the program binary
There’s two ways to get the application binary.
One way is to build it locally.
Instructions on how to do this can be found on Building.
Alternatively, pre-built binaries can be found on the releases page on GitHub.
Once you have a csb
binary, you can verify that it works by running ./csb --help
.
If this command outputs a help menu, you can move on to the next step.
Configuring the .env file
For the application to be able to communicate with Contentstack and access its own database, a .env
file is required.
An example .env
file can be found in the GitHub repository.
Once the .env
file has been configured, you can validate it by running ./csb check:health
.
For more information about the possible configuration options, please see the Configuration options page.
Populating the database
Now that the application is configured, we can create the necessary database tables.
This can very easily be done by running ./csb migrate:db
.
Once this is done, all of the database tables will be set up and ready to go.
Synchronising the Contentstack data
Now that we have a database and tables, we need to populate the data.
We can do this by running ./csb remote:sync
.
This will synchronise the remote data into the database.
This is needed for the built-in API to work, among other things.
This command should also be ran periodically, to keep the data up-to-date.
When run again, the sync will continue where it left off,
so only the initial synchronisation will be a heavy operation.
Subpages
Building instructions for the application
Configuring the Contentstack Bridge
An overview of all possible configuration options
Subsections of Getting Started
Building
To build the application, simply run go build
.
This will create a new file, called csb
. Running it now will throw an error,
since there is no configuration yet.
Instructions on how to configure the application can be found on the Configuration page.
Configuration
Setting up the .env file
Configuration is done with a .env
file. To start, copy the .env.example
:
An example .env
file can also be found in the GitHub repository.
Contentstack credentials
The Contentstack credentials can be obtained from the Contentstack settings.
To reach the settings, go to your stack and click on the settings icon from the left sidebar.
The API Key (CS_API_KEY
) can be found on this page.
For the delivery token (CS_DELIVERY_TOKEN
), click on “Tokens” in the settings page.
If no delivery token exists, please create one by clicking on the top right button first.
Once you have a delivery token, you can click on it, and find it in the field “Delivery Token”.
The region (CS_REGION
) can be found directly in the URL.
It should look like <REGION>-app.contentstack.com
. The <REGION>
here is the region you need to use.
if the URL is app.contentstack.io
, the region will be us
.
Database credentials
When testing the application locally, the DB_*
variables can be left as-is.
This will create a file called db.sqlite3
. This can be handy for local testing.
For production use, databases like MySQL and Postgres are supported as well.
For testing, alternative databases can quickly be spun up locally:
Configuration options
Key | Example value | Description |
---|
CS_API_KEY | - | The API key for the Contentstack stack |
CS_DELIVERY_TOKEN | - | The Contentstack delivery token, used to fetch content |
CS_MANAGEMENT_TOKEN | - | The Contentstack management token, mainly used when creating content types in the CLI |
CS_BRANCH | main | The branch of the Contentstack stack to use |
CS_REGION | us / eu / azure-na / azure-eu | The region your Contentstack is located in. Visit Configuration for more information |
DB_CONN | file:db.sqlite3 | The database connection string |
DB_TYPE | sqlite3 / mysql / postgres | The type of the database to connect to |
DEBUG_AUTH_BYPASS | true / 1 | DEBUG: Disable authentication checks in the API server |
Subsections of CLI
Options
Global flags
--env-file
- Specify a different location of the
.env
file. Defaults to the location of the executable
--quiet
- Only log output with a level of
warning
or above
--verbose
- Log all ouput, including the most verbose messages
Subcommands
check:health
Check the health of the application and the configuration.
Useful when configuring or updating the application.
Flags
–
migrate:db
Perform database migrations. This will be needed during the initial setup,
as well as during future updates.
Flags
--reset
- Revert any previously done database migrations before applying the migrations. WARNING: This will delete any existing data in affected database tables.
remote:setup
Set up or update necessary config in Contentstack.
This command is idempotent, so running it multiple times will not break anything.
Flags
--reset
- Revert any previously done database migrations before applying the migrations. WARNING: This will delete any existing data in affected database tables.
remote:sync
Synchronise all Contentstack entries into the database.
By default, this will be incremental, meaning that every synchronisation action will continue where the last one left off.
Flags
--reset
- Synchronise all data, instead of starting from the last sync token
server
Run a webserver with a REST API. More information about the webserver can be found on the API Server page.
Flags
--port
- The port to run the server on. Defaults to
4000
create:content-type
Create a new content type, with some standard fields.
Flags
--name
- The title of the content type to create
--machine-name
- The machine name of the content type to create
--dry-run
- Log the actions instead of actually running them
API Server
The API server allows the Contentstack Bridge to be used as an alternative to the Contentstack API. This has a couple of advantages:
- Querying arguably becomes a lot easier, since the content type is no longer required in a URL query
- Data can be transformed locally, since it’s stored in a local database
- Full URLs can be saved, using a parenting system within the content types of entries
All requests require a header Authorization
. The value should be equal to the Contentstack delivery token.
Subpages
An overview of all the API endpoints
A list of possible response types