How to check if a pull request passes branch protection rules?

Hello,

I’m writing an app that lets a user perform an action on a branch before merge but I want to perform that action only if the pull request is valid according to branch protection rules (for example, it has approvals).

Is this possible via the GitHub API? Am I misunderstanding something about branch protection?

Thank you