Fix the BadGateway error in Power Automate
Short answer: a 502 BadGateway error means the connection between Power Automate and the other service failed, and Microsoft's table of error codes says "Usually transient. Enable retry on the action." Resubmit the run, turn on a retry policy on that action, and send fewer, smaller requests. On an Excel step, also check that the workbook is not in read-only mode. Then add an alert so a failed run does not go unseen.
What the error means
You open a failed run and one step has a red mark. The message says 502 or BadGateway. Nothing in your flow looks wrong. The same flow worked yesterday.
Microsoft's page "Fix connection failures in cloud flows" lists the 502 error code like this. Meaning: "The connection between Power Automate and the target service failed." Most likely fix: "Usually transient. Enable retry on the action. If it happens consistently, check network/firewall settings (especially for on-premises gateways)."
Microsoft's page "Troubleshoot a cloud flow" says: "If the error code 500 or 502 appears, the failure is temporary or transient. To try the flow again, select Resubmit."
A temporary failure means the step may work if you run it again. It does not mean your flow design is broken. But if the error returns every day, treat it as a pattern and use the steps below.
Signs this is happening to you
- One action fails with 502 or BadGateway, and the actions after it are skipped.
- The error comes and goes. A resubmit works.
- It happens on an Excel step, a SharePoint step or a step that calls another service.
- It started when the list or workbook grew, or when more people began to use the flow.
Step 1. Resubmit the run
- Open https://make.powerautomate.com and sign in.
- Select My flows, then select the flow that failed.
- In the 28-day run history, select the failed run.
- Open the failed step and read the error on the right.
- Select Resubmit.
Microsoft's troubleshooting page describes this path for 500 and 502 errors. Exact names may differ on your screen.
If the resubmit works, the failure was temporary. Go on to Step 2 so you do not have to resubmit every time.
Step 2. Turn on a retry policy for that action
A retry policy tells Power Automate to try the same action again after a short wait. Microsoft's page "Employ robust error handling" says: "Retry policy in flow settings allows you to retry an action at either fixed or exponential intervals." It also says: "Exponential retry policies are preferred because they can extend the retry period over time and increase the chances of successfully completing the action."
Microsoft says to set it in the action's settings: "Configure the retry policy in the settings of the action you want to apply it to. Set the initial interval, or the time before the first retry, and the maximum retry count, or the maximum number of times the action will be retried."
To do this, open the flow in edit mode, select the action that failed, open its Settings and find Retry policy. Pick Exponential, set a count and save.
Microsoft's page "Limits of automated, scheduled, and instant flows" gives the limits. For Medium and High performance profiles, the default policy "sends up to 12 retries at exponentially increasing intervals". For the Low profile, it "sends up to two retries". For the retry settings you can change, Microsoft lists: Retry attempts 90, Retry maximum delay "One (1) day", Retry minimum delay "Five (5) seconds".
Your performance profile depends on your plan. Check with your admin if you do not know it.
One way to start: pick a small count, such as 4, and a minimum interval of 5 seconds, then watch the run history for a week. This is our advice, not a Microsoft rule.
Step 3. On an Excel step, check read-only mode
Microsoft's page for the Excel Online (Business) connector lists 502 BadGateway under common errors: "These errors will display if the spreadsheet is in read-only mode." The same page says: "Write access to a file is required for all actions, otherwise Graph API would return 403 Forbidden error. Also, connector will return the 502 BadGateway error if the spreadsheet is in a read-only mode."
So check these:
- Open the workbook. Is it marked read-only, or open in view mode?
- Does the account in the flow's connection have edit rights to the file?
- Is the file in a place where the connection can reach it, such as a SharePoint library or OneDrive for Business?
For a full list of Excel row problems, see "Power Automate cannot add a row to my Excel table: causes and fixes".
Step 4. Check the Excel file size and speed
The same Microsoft page lists limits that can slow an Excel step:
- "The maximum size of an Excel file that is supported by the Excel Online (Business) connector is 25 MB."
- "The maximum supported size of each connector request is 5 MB."
- "An Excel file may be locked for an update or delete up to 6 minutes since the last use of the connector."
- Throttling: API calls per connection, 100, per 60 seconds.
The page also says: "The connector timeout caused by re-calculations can occur if either there are complicated formulas, or there are too many rows in the worksheet." Its suggestions are to simplify the formulas, or set the workbook calculation mode to Manual.
For long operations, Microsoft's page says: "If there are continuous 504 errors, customers might face throttling due to different Graph API restrictions." Its suggestions are to make the table as simple as possible with fewer formulas and dependencies, or to use another empty worksheet or workbook with the same table format if the row count is large.
One way to start: keep each Excel file small, and keep the data in a real table with few formulas. If the data keeps growing, a SharePoint list is built for this job. See "Replace a spreadsheet tracker with a SharePoint list".
Step 5. Send fewer requests and smaller batches
Too many calls can bring on throttling errors. Microsoft's Excel connector page says of the 429 error: "If throttling is occurring, it is suggested to add explicit delays around the connector action." Microsoft's page "Fix connection failures in cloud flows" says to "Add a Delay action before the failing action, or enable retry policy with exponential backoff on the action's settings. For flows processing many items, add a delay inside Apply to Each."
Ways to send fewer requests:
- Ask for fewer rows. In a SharePoint Get items action, use Filter Query so SharePoint sends only the rows you need.
- Set Top Count to a number a little above the most rows you expect. Microsoft says the default item limit is 100, and: "If you are working with large lists, you can increase this limit up to the list view threshold limit of 5,000." Turn Pagination on if you need more. See "Power Automate Get items stops at 100 rows: how to get them all".
- For the Excel action "List rows present in a table", Microsoft says: "The List rows present in a table action returns up to 256 rows by default. In order to get all rows, turn on pagination." Use Filter Query and Select Query there too. Microsoft notes that Select Query takes a comma-separated list of columns, and that the first 500 columns are returned by default.
- Process the rows in small groups. For example, run the flow on a schedule and handle 50 rows each time, then mark them as done.
- Add a short Delay inside a loop that calls the same service again and again.
For the SharePoint connector, Microsoft's page lists "API calls per connection" as 600 per "60 seconds".
Do not run many copies of the same flow at once against one file. Microsoft's Excel page says: "Simultaneous file modifications made by other connectors, or manual edits are not supported."
Step 6. Check network and permissions
Microsoft's table says that if the 502 "happens consistently", you should "check network/firewall settings (especially for on-premises gateways)". If your flow reaches a service through an on-premises data gateway, ask your admin to check that the gateway machine is on and has internet access. Microsoft's page, for the SQL Server connector, says to check the gateway machine and "Restart the On-premises Data Gateway service".
Microsoft's page on HTTP and custom connectors also lists an IP allowlist problem: "The target API only allows specific IP addresses. Add Power Automate's IP ranges for your region." The symptom it gives is "403 or connection timeout".
Step 7. Check the service status
For a 500 error, Microsoft's table says to wait and retry, then check the Microsoft 365 Service Health dashboard. Our advice, not a Microsoft rule: for a 502 error too, if many flows fail at the same time, ask your admin to check service health at https://admin.microsoft.com/Adminportal/Home#/servicehealth before you change any flow.
Step 8. Add an alert so you know when it fails
A retry will not save every run. Add an alert so a failure does not sit unseen. Microsoft's page "Fix connection failures in cloud flows" gives these steps:
- In the designer, add a parallel branch after the action most likely to fail.
- Select the three dots on the new branch's first action, then Configure run after, and check only has failed.
- Add a Send an email action, or post to Teams, with a subject such as "Flow failed" and the error details.
Microsoft's page "Employ robust error handling" also describes grouping actions in a Try scope and a Catch scope: "Configure the "Catch" scope to run if the "Try" scope fails."
For a failed run that only shows "An action failed. No dependent actions succeeded.", see the guide with that title: "Error: "An action failed. No dependent actions succeeded."".
500, 502 and 504 side by side
- 500 Internal Server Error. Microsoft's table says: "The target service is experiencing issues." Its fix is "Wait 15-30 minutes and retry."
- 502 Bad Gateway. "The connection between Power Automate and the target service failed." The fix is "Usually transient. Enable retry on the action."
- 504. Microsoft's Excel page says requests "taking longer than 30s might return 504" and that "continued 504's would result in throttling". For SFTP, Microsoft lists a 504 when the connector "can't successfully establish a connection" to the server.
What to check by connector
SharePoint. The connector allows 600 API calls per connection per 60 seconds. Ask for fewer rows with Filter Query, as in Step 5, so each call stays small. For a loop over many items, add a Delay inside it.
Excel. Read Steps 3 and 4: read-only mode, the 25 MB file limit, the 5 MB request limit and slow formulas.
Run script. Microsoft's Excel page says: "Run script operation allows up to 3 calls per 10 seconds and up to 1600 calls per day." It also lists a request to the script service as throttled when there are "more than 3 within 10 seconds". If a loop calls Run script, add a Delay inside it, and keep the calls to a handful per 10 seconds.
HTTP. Microsoft's error reference lists an HTTP action "calling a slow external API with default 100-second timeout" as a cause of ActionTimedOut. For a slow API, see "My Power Automate flow run timed out: what it means and how to fix it". Microsoft's page for the HTTP with Microsoft Entra ID connector lists 100 API calls per connection per 60 seconds.
SFTP. For a 504 on an SFTP step, Microsoft's SFTP-SSH page says: "The connection timeout is 20 seconds." It suggests these checks:
- Check whether your SFTP server limits the number of connections from each IP address.
- If a firewall is in place, add the managed connector IP addresses for your region to the approved list.
- If the error is intermittent, raise the Retry policy count above the default of four retries.
- Read the SFTP server log to see whether the calls arrive.
What to avoid
- Do not set the retry count very high. A long retry on a step that is truly broken just delays the alert.
- Do not retry a step that adds a row without a plan for repeats. Microsoft warns that when the Excel connector times out on a large workbook, "data can be inserted multiple times because of retry policy".
- Do not call one Excel file from many flows at once.
- Do not fetch every row and filter later. Filter in the action.
- Do not ignore a pattern. If the same step fails every day, find the cause in Steps 3 to 6.
- Do not leave the flow with no failure alert.
Honest limits
Retries and smaller batches lower the number of failures. They do not promise zero. A 502 can come from the other service, and you cannot fix that part. Your job is to make the flow recover on its own where it can, and to tell you when it cannot. If one flow carries work your team cannot do without, build it with a failure alert, a log of what ran and an owner who is not a single person.
When to get help
You can build all of this yourself in Microsoft 365. If you would rather have it built and tested for your team, I do that. A tracker like this is a fixed price: $5,000 for one, built in 2 weeks. See "What a SharePoint tracker costs to build". Bring one example of the problem to a free call.
I am Al Davies. I run 250 High Street LLC and build SharePoint trackers and Power Automate flows for operations teams. I work remotely. The first call is free, and I will not try to sell you anything.
See trackers I built: Tools I built
FAQ
Is a BadGateway error my fault?
Microsoft's troubleshooting page says a 500 or 502 error means "the failure is temporary or transient" and tells you to select Resubmit. Your flow may still make it worse, for example by sending too many calls at once or by reading a very large Excel file. Use Steps 4 and 5 to check.
What does BadGateway mean on a SharePoint step in Power Automate?
Microsoft's table lists 502 as a failed connection between Power Automate and the target service, usually transient. Resubmit, turn on retry, and ask SharePoint for fewer rows with Filter Query.
Does the Excel BadGateway error mean the file is corrupt?
Not by that error alone. Microsoft's Excel connector page ties 502 BadGateway to a spreadsheet in read-only mode. Check the file mode and the connection's edit rights first.
What is the difference between a 500, 502 and 504 error in Power Automate?
Microsoft's table says 500 means the target service has issues, so wait and retry. It says 502 is a failed connection, usually transient. Microsoft's Excel page ties 504 to requests that run longer than 30 seconds.
Why does an SFTP step in Power Automate show a 504 or timeout?
Microsoft's SFTP-SSH page says the connector times out after 20 seconds of trying to connect. Check the server's per-IP connection limit, add the connector IP addresses to the firewall approved list, and raise the retry count.
Sources
- Microsoft Learn, Fix connection failures in cloud flows
- Microsoft Learn, Troubleshoot a cloud flow
- Microsoft Learn, Employ robust error handling
- Microsoft Learn, Limits of automated, scheduled, and instant flows
- Microsoft Learn, Excel Online (Business) connector
- Microsoft Learn, SharePoint connector
- Microsoft Learn, Cloud flow error code reference
- Microsoft Learn, SFTP - SSH connector
- Microsoft Learn, HTTP with Microsoft Entra ID (preauthorized) connector
- Microsoft Learn, In-depth analysis into 'Get items' and 'Get files' SharePoint actions for flows in Power Automate