Cancel An Approval In Power Automate
You can cancel an approval in Power Automate by using a single flow action. This ability is not included in the standard approvals actions. However, we can invoke an HTTP request to call the Microsoft Teams approvals API and cancel the request.
Table of Contents
• Introduction: The Cancel An Approval Flow
• Choose An Approval To Be Cancelled
• Get The Approval Id For The Approval To Be Cancelled
• Make A Connection To Microsoft Teams Approvals
• Cancel An Approval In Power Automate Using An HTTP Request
• Run The Cancel An Approval Flow In Power Automate
Introduction: The Cancel An Approval Flow
An employee at a financial services firm makes a travel request to their manager using Microsoft Teams approvals and then leaves the company. We will cancel the approval by creating a Power Automate flow.
Choose An Approval To Be Cancelled
An approval may only be cancelled when it is in requested status. Open Microsoft Teams approvals center and find a “requested” approval.
Or create a new approval request if there are no approvals with a requested status. Here’s an example that can be copied if needed.
Get The Approval Id For The Approval To Be Cancelled
To cancel an approval using Power Automate we will need to get the Approval’s unique ID. Go to make.powerautomate.com and navigate the Approvals table (in Dataverse). Search the table for the record with a matching Title. The unique identifier is located in the Approval field of the record.
Set The Approval ID And Flow Environment Variables
Now we have the information needed to make our Power Automate flow. Start a new instant flow and add an initialize variable step. Create a variable named varApprovalId and set the value to the unique identifier of the approval.
Then initialize another variable named varFlowEnvironment and set the value to the unique identifier of the current environment.
The unique identifier for the current environment can be obtained by using the following expression.
workflow()?['tags']?['environmentName']
Make A Connection To Microsoft Teams Approvals
An approval cannot be cancelled using the standard Microsoft Teams actions included in Power Automate. We will use the HTTP With Microsoft Entra ID (Pre-authorized) – Invoke An HTTP Request action to cancel an approval instead.
Upon adding the action we will be asked to setup a connection.
Use the following URL in both the Base Resource URL and Microsoft Entra ID Resource URI fields and press the Sign In button.
https://approvals.teams.microsoft.com
Cancel An Approval In Power Automate Using An HTTP Request
Fill-in the flow action with the following values to cancel the approval request.
Method:
DELETE
Url of the request:
https://approvals.teams.microsoft.com/api/cancelApproval/@{variables('varApprovalId')}?flowEnvironment=@{variables('varFlowEnvironment')}
Headers:
Key | Value |
Accept | application/json |
Run The Cancel An Approval Flow In Power Automate
That’s all it takes to cancel an approval using Power Automate. Save the flow and give it a test run.
After the flow is completed we can see the approval has been cancelled in the Teams Approvals Center.
And the cancellation, who performed and the timestamp are reflected in the approval details.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps & Power Automate articles sent to your inbox each week for FREE
Questions?
If you have any questions or feedback about Cancel An Approval Flow In Power Automate please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.
Hi Matthew, This is a very needed solution so thank you for posting it. I do have a question though. Is the HTTP request in this solution a premium connector?
Kurt,
Yes, the HTTP action in this flow is a premium connector.
If you use this as part of an automated or scheduled flow it will only require the flow owner to be licensed.
But if you do this as part of an instant or Power Apps triggered flow all users would require a premium license.
is there any way to post HTML with the approval creating on teams? similiter to this issue as adaptive cards is not an option
https://powerusers.microsoft.com/t5/Building-Flows/post-a-choice-of-options-as-the-Flow-bot-to-a-user-HTML-format/td-p/960391
Ramos,
Teams approvals will only accept markdown. HTML support is not available.
Hello Matthew,
First of all thanks for sharing this great post.
I would like to ask if there is an opportunity to delete an approval.
Thanks.
Aris,
This is possible if use the Dataverse – Delete a row action on the Approval table.
Hi, is it possible to create/instantiate a flow in another environment?
Oliveira,
I don’t understand your question or its relevance to this post. Please explain.
Hi Kurt,
Incredibly useful, thankyou.
We’re getting this error on the HTTP Request action.
Do you know what causes this?
Paul,
I do not know what causes this message. It looks like a permissions issue.
Start by using a service account that has a Microsoft Teams license and System Administrator privileges.
We are running into the same error when canceling approval requests using the HTTP action. We use a system admin account with a Teams license and a Power Automate premium license.
Is there any official documentation about this and other API methods relating to approvals? I can only find this blog post and some forum questions regarding this. I’m curious what else is possible using a Teams Approvals API.
Lucas,
Nope, this is all stuff I’ve discovered through inspecting my web browser activity. Although the Microsoft 365 roadmap shows the Approval API will be added in July 2024. I suspect it will be very robust.
why not to use this?
Ramos,
My action cancels an approval. Your action cancels a flow.
Hi, I am not sure what information/details to use for the workflow()?[‘tags’]?[‘environmentName’]
Jeroen,
It’s a Power Automate expression that will evaluate as needed. You will not need any additional details to get it working 🙂
Thank you for this great example, Matthew. Sadly, I’m on a government tenant which does not allow me access to the underlying Dataverse tables. I think I’m SOL until MS exposes functionality to cancel an automation. Any pull you have to make that happen would be appreciated!
HI, nice solution to cancel approvals, there is another way to cancel it? Can’t use CDN because approvals requestor are external users without licence (guesters) using a sp list that triggers a flow approval, and I not sure where is saved the approval or approval request that i need to check approval state and cancel.
Angel,
The only other way to cancel it this moment is to change the Approval record status to Inactive and the State Code to Cancel in Dataverse. The API I provided does it for you but you can do it “manually” too.
Hi Matthew, this article surely saved my day. Until now I was cancelling approvals with the Dataverse connector, by directly updating the approval row. While it was never supported, it worked well so far until now. The problem is that MS made some changes to the approvals functionality and now if you cancel things that way, the request appears cancelled to the user on teams, but the “Wait for an approval” component of the flow never gives an output and stays indefinitely on waiting status.
I replaced the dataverse update row by the API call as you suggested and it worked like a charm.
Thank you!
Hi Matthew, thank you for this!!! So helpful, you have no idea 🙂
Can we use the Invoke an HTTP request to also approve/reject approvals or only cancel them?
Iga,
This would work with the approver’s account logged in but I have no idea if it can be done through a service account.
URI
https://approvals.teams.microsoft.com/api/UpdateApproval
POST
Headers:
Content-Type: application/json
Body
{
“ApprovalId”: “ecaa9c15-2f22-4100-ae93-9f08e636ed4b”,
“Properties”: {
“Response”: “Approve”,
“Comments”: “”
},
“FlowEnvironment”: null
}
Just curious, could you walk through how you managed to figure out the API calls/endpoints?
Ken,
By opening Microsoft Teams in Chrome, performing an action, and then inspecting the network traffic after executing the action in Chrome developer tools.
Hi Matthew,
great post thank you!
I try to reproduce your steps but I get an error on Http request box:
Trying the same step with GET instead DELETE and using /api/GetApprovalDetails/varName as path, it works.
What is wrong on delete? 🙁
Hi Matthew! What is the benefit of using this api call over updating the dataverse tables directly?
Bridgette,
An API call abstracts what might be multiple operations into a single operation. If you are doing the same steps as the API there would not be any different. But it sure is convinient.
Hi Matthew, thanks for the post, very informative! From my testing this update only applies to the teams UI? The approval still appears in the persons Power Automate Approvals and is available to take action on (i.e. approve or reject). If correct or did I do something wrong?
Hi Matthew, I used your API call & it worked great. If I need to add a comment when the approval is being deleted, how is the “Body” of the HTTP action setup? I mean, is there a “Comments” field and is it an attribute or is it under other attributes?
Hi Matthew:
Is there an equivalent API endpoint for submitting a response to an approval (i.e. some URL that looks like “https://approvals.teams.microsoft.com/api/submitResponse/…”)?
I cannot seem to find any documentation on other actions that utilize the Approvals API in the way that you are using it.
Henry,
Yes, but it’s in beta right now. Try this once it goes to production:
https://learn.microsoft.com/en-us/graph/api/approvalitem-post-responses?view=graph-rest-beta
Hi Matthew, thank you for this post. Is there any chance to use a non premium connector? The approval API has been rolled out?
Jacopo,
The Approvals Graph API is currently available in beta. Using it will require a premium license.
https://learn.microsoft.com/en-us/graph/api/approvalitem-cancel?view=graph-rest-beta&tabs=http
I am getting a “The Response is not in a JSON format.” error. My guess is the service account I am running this does not have the necessary permissions. If I want to cancel this on behalf of another user, is there a 365 admin role that would grant the service account the necessary permissions?