I am trying to send message on teams using a python script using Power Automate.
import requests # Import requests library
import datetime
# Get current time.
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Triggering Power Automate Flow
flow_url='https://***/triggers/manual/paths/invoke?api-version=2016-06-01' # Replace with actual URL from step 2
response=requests.post(flow_url,json={"status":"Script Completed","timestamp":now})
if response.status_code==200:
print('PowerAutomate Flow triggered successfully')
else:
print(f'Failed to trigger PowerAutomate Flow: {response.status_code}')
Error:
Failed to trigger PowerAutomate Flow: 401
Power Automate Flow:
Full Flow:
Ok, so first issue has been solved by updating your URL as instructed.
Next, the 202
isn't an error, it means that the request has been accepted and the flow will run asynchronously.
If you want to wait and return values or a successful (200
) response to your calling application then you need to put a Response
operation in the flow at the point where the response needs to be made. It's awesome architecture, you can put it anywhere you want and the flow will keep running.
Not adding that in your flow will generate an immediate 202
and respond directly to your calling application.