Automating transactional email template updates using GitHub Actions and AutoSend REST API

What is the best workflow to store HTML email templates in Git repositories and deploy template updates to AutoSend automatically during CI/CD?

CI/CD for Email Templates

Managing email templates in Git ensures version control, peer review via Pull Requests, and automated deployments to AutoSend.

GitHub Actions Workflow (.github/workflows/deploy-templates.yml):

name: Deploy AutoSend Templates

on:
  push:
    branches: [ main ]
    paths:
      - 'templates/**'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Deploy Templates to AutoSend
        env:
          AUTOSEND_API_KEY: ${{ secrets.AUTOSEND_API_KEY }}
        run: |
          for file in templates/*.html; do
            template_id=$(basename "$file" .html)
            content=$(jq -Rs . < "$file")
            
            curl -X PUT "https://api.autosend.com/v1/templates/$template_id" \
                 -H "Authorization: Bearer $AUTOSEND_API_KEY" \
                 -H "Content-Type: application/json" \
                 -d "{\"html\": $content}"
          done

Benefits:

  • Eliminates manual copy-pasting of HTML between local code editors and dashboard UI.
  • Enables unit testing of local email templates before merging.