GitHub Actions fails for Azure SWA

Markus Senn 0 Reputation points
2025-11-13T13:43:10.9466667+00:00

Hi all

I am trying to deploy my Next.js project to Azure SWA, which I had been able to in the past. I was gone for 3 months and now I am having trouble getting the pipeline to work again. I had an error in the deploy phase that read along the lines of 'invalid API token'. For this I already double & triple checked the deployment token and GitHub secret (with no success), then created a new SWA deployment which now shows the new error:

Try to validate location at: '/github/workspace'.

App Directory Location: '/' was found.

Try to validate location at: '/github/workspace/swa-db-connections'.

Looking for event info

The content server has rejected the request with: BadRequest

Reason: No matching Static Web App was found or the api key was invalid.

I changed all the necessary variables, but I am making no progress. Attached the yaml file.

azure-static-web-apps-xxx.txt

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jerald Felix 9,835 Reputation points
    2025-11-14T00:25:57.01+00:00

    Hello Markus Senn,

    Thanks for raising it in Q&A forum. The "BadRequest: No matching Static Web App was found or the api key was invalid" in your GitHub Actions workflow for Azure SWA deployment after a 3-month hiatus is typically caused by an expired or mismatched deployment token—Azure rotates tokens periodically, or the one stored in GitHub secrets is invalid after repo/SWA changes. Here's a short fix sequence:

    Quick Steps to Resolve

    1. Reset the Deployment Token:
      • In Azure portal > Your SWA resource > Overview > Manage deployment token > Reset token > Copy the new token (valid for 6 months).
      • This regenerates a fresh API key tied to your SWA.
    2. Update GitHub Secrets:
      • Go to your GitHub repo > Settings > Secrets and variables > Actions > Find AZURE_STATIC_WEB_APPS_API_TOKEN_{random} (or similar) > Update > Paste the new token > Save.
      • If multiple secrets (for branches/PRs), update all matching ones.
    3. Verify YAML Workflow:
      • In .github/workflows/azure-static-web-apps-{token}.yml, ensure:
        
             - name: Build And Deploy
        
               id: builddeploy
        
               uses: Azure/static-web-apps-deploy@v1
        
               with:
        
                 azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_{your-token} }}
        
                 app_location: "/"  # Your app root
        
                 output_location: "build"  # Or dist/ for Next.js
        
                 action: "upload"
        
        
        • Remove any github_id_token if present (causes conflicts).
      • Commit/push to trigger; check Actions logs for token validation.
    4. Reconnect Repo if Needed:
      • SWA > Configuration > Repository details > Disconnect > Reconnect to GitHub > Select branch/repo.
      • This re-syncs and may auto-update the token secret.
    5. Test Deploy:
      • Run workflow manually (Actions > Select workflow > Run workflow).
      • If fails: Check logs for token mismatch; delete/recreate SWA if corrupted (exports config first).

    This resolves 95% of token errors—test after step 2. Kindly approve this answer if you feel it is helpful.

    Best Regards,

    Jerald Felix


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.