Skip to content
New Webhooks added: Inventory and Order modifications. Check the changelog →
Cartly Developers

GitHub Theme Sync

Connect a theme to a GitHub repository. Any git push automatically deploys updated theme files to your Cartly store.

Setup

GitHub theme sync is configured on the Cartly platform, not per store. A self-hosted deployment needs three environment variables:

GITHUB_CLIENT_ID=your-oauth-app-id
GITHUB_CLIENT_SECRET=your-oauth-app-secret
GITHUB_WEBHOOK_SECRET=your-webhook-secret

Create a GitHub OAuth App at Settings → Developer Settings → OAuth Apps with the callback URL https://your-platform-domain/api/github/callback. Cartly requests the repo scope.

You do not create the push webhook by hand: when a repository is imported or connected, Cartly registers it for you through the GitHub API, pointing at https://your-platform-domain/api/webhooks/github and signed with GITHUB_WEBHOOK_SECRET. The URL is one global endpoint for all stores and carries no shop id.

All /admin/theme/... endpoints below authenticate with the merchant admin JWT (Authorization: Bearer ...).

GET/admin/theme/github/connectadmin-jwt

Returns {"redirect_url": "https://github.com/login/oauth/authorize?..."}. Send the merchant's browser to that URL; GitHub redirects back to /api/github/callback, which stores the encrypted token for the shop. Returns 503 if GITHUB_CLIENT_ID is not configured.

GET/admin/theme/github/reposadmin-jwt

Lists the repositories accessible to the connected GitHub account. Branches of one repo: GET /admin/theme/github/repos/:owner/:repo/branches. Connection state: GET /admin/theme/github/status. Drop the stored token: POST /admin/theme/github/disconnect (owner/admin).

POST/admin/theme/github/importadmin-jwt

What the admin UI uses: creates a NEW unpublished theme from a repository and branch (owner/admin only). Verifies that the repo and branch are reachable with the connected token, registers the push webhook, and starts the initial sync. Returns 201 with {id, name, sync_status}. branch defaults to main.

Request Body

json
{
  "branch": "main",
  "repo": "owner/repo-name"
}
POST/admin/theme/library/:id/github-connectadmin-jwt

API only (the admin UI imports a new theme instead): links an existing theme install to a repo and branch (owner/admin only). Auto-deploy on push is always switched on. Registers the push webhook and starts the initial full sync workflow (activity timeout 5 min), which makes the repository the source of truth: theme files missing from the repo are removed. AI drafts (working copies) answer 409 with code working_copy.

Request Body

json
{
  "branch": "main",
  "repo": "owner/repo-name"
}
POST/admin/theme/library/:id/github-syncadmin-jwt

Manually re-runs the full sync from the connected branch (owner/admin only). Returns {ok: true, sync_status: "pending"}; 400 if the theme is not connected to GitHub.

POST/admin/theme/library/:id/github-disconnectadmin-jwt

Clears the repo link (owner/admin only). Files already synced stay in the theme and become editable again.

Repository Structure

Sync is one-way, GitHub to Cartly. Put the theme folders at the repository root: layouts/ (or Shopify-style layout/), templates/, sections/, snippets/, blocks/, assets/, config/ and locales/. layouts/theme.liquid (or layout/theme.liquid) is required, otherwise the sync fails validation. Repo housekeeping such as .git, .github, README.md, LICENSE, node_modules and package.json is ignored.

Files with an unsafe path, Liquid files over 256 KB and any other file over 5 MB are skipped and listed in sync_error_log.

Push Webhook

GitHub sends push events to the single global endpoint POST /api/webhooks/github (no shop id in the URL). Cartly verifies the signature, answers ping with a pong, and ignores every event except push and every push that is not to a branch (tags). It then finds the theme installs whose connected repository full name and branch match the push and that have auto-deploy on, and starts a GitHubIncrementalSync Temporal workflow for each (activity timeout 2 min). The workflow fetches the files from the commits' added, modified and removed lists and writes them through the theme service as one atomic file set (fork-on-write, audit action THEME_GITHUB_SYNC). The response is {"ok": true, "synced": N}.

Signature Verification

X-Hub-Signature-256: sha256=HMAC-SHA256(body, GITHUB_WEBHOOK_SECRET)

An invalid signature returns 401.

Workflow

The initial and manual sync (GitHubInitialSync) and the incremental sync (GitHubIncrementalSync) run on a dedicated Temporal task queue, and re-running them is safe.

Read-Only Guard

While a theme is connected to GitHub, edits to its files in the code editor or API are rejected with 409 Conflict and code github_readonly. Disconnect the repo to edit the files in Cartly.

GET/admin/theme/library/:id/github-statusadmin-jwt

Returns github_repo, github_branch, last_commit_sha, auto_deploy, sync_status and sync_error_log.

Code Examples

bash
# 1. Get the OAuth URL (open redirect_url in a browser and authorize)
curl -H "Authorization: Bearer $TOKEN" \
  https://cartly.pro/admin/theme/github/connect

# 2. Import the repo as a new theme
curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"repo":"acme/my-theme","branch":"main"}' \
  https://cartly.pro/admin/theme/github/import

# 3. Check sync status
curl -H "Authorization: Bearer $TOKEN" \
  https://cartly.pro/admin/theme/library/{themeId}/github-status