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
- 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.
- 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.
- Go to your GitHub repo > Settings > Secrets and variables > Actions > Find
- 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_tokenif present (causes conflicts).
- Remove any
- Commit/push to trigger; check Actions logs for token validation.
- In
- 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.
- 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