In this post, you will learn how to connect to an API with OAuth 1.0 authentication in Power Automate. Using this connection, we will connect to Twitter API to post tweets with @mentions and also send DMs with quick actions. The Twitter connector available in Power Automate doesn’t allow user mentions and also doesn’t have an action to send DMs.
Currently, it’s not possible to implement OAuth 1.0 directly in Power Automate as the HTTP action doesn’t have this type available in the list of authentication types. To overcome that, we will create an Azure function which connects to the Twitter API and then call the Azure function from Power Automate. Don’t worry if you haven’t created an Azure function before. I will walk through all the steps to create an Azure function as well
Before we start, credits to Michael LaMontagne for his blog post on a similar topic. I could use it fine for posting tweets , however, for sending DMs it got a bit tricky as I had to include some body in the POST requests. Also, credits to Geetha Sivasailam for helping me with some of the PowerShell stuff. I didn’t know anything about PowerShell before this.
Awesome! you have now created a Twitter App.
4. Go to the “Keys and Tokens” section and click on generate to get the access token and access token secret. Copy them and save it securely. Also copy the API Key and API secret key.
Paste this in the Request body –
{ "Resource": "statuses/home_timeline.json", "Method": "GET", "Parameters":"", "PostBody":"" }
This should return an Output with your home timeline of tweets. If it doesn’t , check the steps mentioned above once more and try again to test. If it still doesn’t work, write a comment below with the issue that you are facing.
If it works, YAYYY!!! You have done an awesome job! Now you are ready to use the Twitter API to basically do anything that the API allows.
Before we create the flow , copy the function URL and save it somewhere. You will need it in the HTTP action.
Add the “Manually trigger a flow” trigger and HTTP request as an action.
{
"Resource": "statuses/update.json",
"Method": "POST",
"Parameters":{
"status":"This tweet was posted using an Azure function and @MSPowerAutomate"
},
"PostBody":""
}
Once you have the user id, use the following in the body of the HTTP action.
{
"Resource": "direct_messages/events/new.json",
"Method": "POST",
"Parameters":"",
"PostBody":'{
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "user-id"
},
"message_data": {
"text": "This is a test DM"
}
}
}
}'
}
Power Automate somehow finds this as invalid JSON and thus I followed this approach –
{
"Resource": "direct_messages/events/new.json",
"Method": "POST",
"Parameters":"",
"PostBody":'{
"event": {
"type": "message_create",
"message_create": {
"target": {
"recipient_id": "user-id"
},
"message_data": {
"text": "A DM with option ",
"ctas": [
{
"type": "web_url",
"label": "Open Google.com",
"url": "https://google.com"
},
{
"type": "web_url",
"label": "Open Microsoft.com",
"url": "https://microsoft.com"
}
]
}
}
}
}'
}
You can basically use this to access anything under the Twitter API hood. For more info visit – https://developer.twitter.com/en/docs/api-reference-index
Also, you can follow a similar approach for any other API that uses Oauth 1.0 as the authentication method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.