Power Automate Excel Run Script Error 502 BadGateway

Schwartz, Danielle (she/her) 5 Reputation points
2026-05-28T17:08:23.8266667+00:00

I have multiple flows that run scripts in Excel with no errors, and yesterday they all started failing with error code 502 "BadGateway."

  • I verified that involved files are not read-only.
  • I am able to manually run the scripts in the workbooks (in Excel Online and Excel Desktop).
  • I tried refreshing + adding a new connector and relinking to actions.
  • I tried copy/paste-ing to create new actions with the new connector.
  • I tried re-saving scripts to Sharepoint and calling the action "Run Script from Sharepoint"

Any ideas for how to troubleshoot? Why else might the flow be getting stuck trying to run scripts?

Microsoft 365 and Office | Excel | For business | Windows

2 answers

Sort by: Most helpful
  1. Barend Buizer 6 Reputation points
    2026-05-28T21:09:38.54+00:00

    Dear @Schwartz, Danielle (she/her) ,

    Another user reported a similar issue and a fix that worked for them: https://learn.microsoft.com/en-us/answers/questions/5903740/how-to-fix-502-error-in-power-automate.

    I suggest you try the same fix that worked for the other user.

    Was this answer helpful?

    2 people found this answer helpful.

  2. Kai-L 17,480 Reputation points Microsoft External Staff Moderator
    2026-05-28T19:37:36.2966667+00:00

    Dear @Schwartz, Danielle (she/her),

    Good day, and I appreciate the detailed description of your issue. As a forum moderator, I genuinely wish I could directly access your account or delve into the backend systems to investigate and fix this for you. However, our role here is limited to providing general guidance and solutions that can be applied by users. 

    From my research, the 502 Bad Gateway error in Power Automate can occur for a variety of reasons, depending on what your flow is doing. Even if your flows were working correctly before, this error may appear because of temporary Microsoft service issues on the backend, the workbook being in a co-authoring state or having transient locks, or connector caching issues.

    Please follow these steps to see if they help:

    1.Recreate the Run script action

    • Delete the existing Run script action.
    • Add a new one from the Excel Online (Business) connector.
    • Re-select the file and script.

    2.Check the workbook state

    • double check if there were any other users, Power Automate flows or operations accessing the same workbook at the time when your script was running.
    • Try saving the workbook again in Excel for the web.
    • If the workbook is stored in SharePoint, confirm there are no file sync or editing conflicts.

    To help prevent this kind of error in the future, I recommend:

    • Minimizing the size of the Excel tables being read by archiving old records to a different worksheet or workbook.
    • Scripting against values read into an array, rather than reading cells directly, when possible.
    • Creating child flows to limit the number of Run script connectors in a single flow, where possible.

    Also, as this forum primarily focuses on Office 365 products and their native features, I highly recommend you search for Error 502 BadGateway or posting a new thread in the Power Platform Community, specifically under the Power Automate forum. That space is actively followed by Microsoft MVPs, platform developers, and other experts who regularly work with Power Automate flow issues. Beyond standard troubleshooting, the forum also provides access to a large collection of community-tested solutions and deeper technical discussions for more complex issues. Participating there may also be a great opportunity to learn from experts who solve these exact scenarios daily and further refine your approach.

    I hope this information helps clarify the situation and provides you with practical next steps. Should you have any further questions or need additional assistance, please do not hesitate to reach out. I’m always happy to help.

    Have a wonderful day!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    Was this answer helpful?


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.