CodexBloom - Programming Q&A Platform

GitHub Actions failing to deploy to Heroku with 'Invalid API Key' despite correct setup

👀 Views: 13 đŸ’Ŧ Answers: 1 📅 Created: 2025-09-06
github-actions heroku deployment YAML

I'm attempting to set up Quick question that's been bugging me - After trying multiple solutions online, I still can't figure this out..... I tried several approaches but none seem to work... I've been banging my head against this for hours. I'm having trouble with my GitHub Actions workflow that is supposed to deploy my Node.js app to Heroku after each push to the main branch. I've set up my Heroku API key as a secret in my GitHub repository, but the deployment fails with the error message: `Error: Invalid API key`. Here's the relevant section of my GitHub Actions workflow file `.github/workflows/deploy.yml`: ```yaml name: Deploy to Heroku on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Node.js uses: actions/setup-node@v2 with: node-version: '14' - name: Install dependencies run: npm install - name: Deploy to Heroku env: HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} run: | git remote add heroku https://git.heroku.com/my-app.git git push heroku main ``` I've double-checked that `HEROKU_API_KEY` is set correctly in the GitHub secrets. I even tried regenerating the API key in Heroku, but I still get the same error. I've confirmed that the API key is valid by using it directly in a terminal command to deploy manually. Could there be an issue with the environment variable not being passed correctly in the GitHub Actions context? I've also looked into whether the Heroku remote is set up correctly, but all seems fine. Any ideas on what might be going wrong here? This is part of a larger web app I'm building. Am I missing something obvious? This is my first time working with Yaml stable. I've been using Yaml for about a year now. Is this even possible? The project is a microservice built with Yaml.