Learn how to automate the update of your OpenAPI specification in GitBook
GitBook can work with any CI/CD pipeline you already have for managing your OpenAPI specification. By using the GitBook CLI, you can automate updates to your API reference.
Upload a specification file
If your OpenAPI spec is generated during your CI process, you can upload it directly from your build environment:
# Set your GitBook API token as an environment variableexportGITBOOK_TOKEN=<api-token>gitbookopenapipublish\--specspec_name\--organizationorganization_id\example.openapi.yaml
Set a new source URL or trigger a refresh
If your OpenAPI specification is hosted at a URL, GitBook automatically checks for updates. To force an update (for example, after a release), run:
# Set your GitBook API token as an environment variableexportGITBOOK_TOKEN=<api-token>gitbookopenapipublish\--specspec_name\--organizationorganization_id\https://api.example.com/openapi.yaml
Update your spec with GitHub Actions
If you’re setting up a workflow to publish your OpenAPI spec, complete these steps in your repository:
In your repo, go to “Settings → Secrets and variables → Actions”.
Add a secret: GITBOOK_TOKEN (your GitBook API token).
Add variables (or hardcode them in the workflow):
GITBOOK_SPEC_NAME → your spec’s name in GitBook
GITBOOK_ORGANIZATION_ID → your GitBook organization ID
Save the workflow file as .github/workflows/gitbook-openapi-publish.yml.
Push changes to “main” (or run the workflow manually).