Project EST – Part 03 – Logic App

No Comments on Project EST – Part 03 – Logic App

As described in part 1 and part 2, my Schedule Tweets solution doesn’t look that bad. But one important component is still missing: sending the tweets…

To Flow or not to Flow…

At first I thought about sending the tweets via Microsoft Flow. But then I had to find out some things:

  • Flow is not unlimited and has its own licensing model … was personally new to me … but it is also not my business
  • with the flow contained in O365 you get a maximum of 2000 executions per month
  • I want to check my list several times per hour … starting a check every 15 minutes means = 4 x 24 x 30 = 2880 Runs
  • the restriction that Premium connectors cannot be used in the Free Tier
  • this is probably not the last flow … so I would like to have some room to maneuver.

So we had to find another solution…and because Flow in the background is only based on Logic Apps…then we take the…

Well, of course … Logic App

Thanks to the Consumption Model I can do what I want in the Logic App…it is regularly charged against my Azure Subscription…and there are no limits anymore.

So here we go. First create a Logic App and then start the Logic App Designer.

The basic structure was clear quite quickly…I periodically check the list elements and receive the info and then process the elements accordingly:

Now some conditions had to be queried and branches had to be established:

  • first only the list elements that have not yet been sent are processed –> a check is carried out for the Boolean value of “Sent”
  • then only those elements are further processed that have a send date in the past or are now sent
  • then the corresponding graphic attachment must be read for each current element
  • the tweet must be sent
  • Finally, the “Sent” value in the SharePoint list must be set to “true

All in all, it looks like this.

And the tweets are already working… To be on the safe side here again the code of my Logic App

{
    "$connections": {
        "value": {
            "sharepointonline": {
                HAVEYOUROWNCONNECTIONHERE            },
            "twitter": {
                HAVEYOUROWNCONNECTIONHERE            }
        }
    },
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Apply_to_each": {
                "actions": {
                    "Condition": {
                        "actions": {
                            "Condition_2": {
                                "actions": {
                                    "Apply_to_each_2": {
                                        "actions": {
                                            "Get_attachment_content": {
                                                "inputs": {
                                                    "host": {
                                                        "connection": {
                                                            "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                                                        }
                                                    },
                                                    "method": "get",
                                                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('YOUR URL'))}/tables/@{encodeURIComponent(encodeURIComponent('YOUR UID'))}/items/@{encodeURIComponent(encodeURIComponent(items('Apply_to_each')?['ID']))}/attachments/@{encodeURIComponent(items('Apply_to_each_2')?['Id'])}/$value"
                                                },
                                                "metadata": {
                                                    "flowSystemMetadata": {
                                                        "swaggerOperationId": "GetAttachmentContent"
                                                    }
                                                },
                                                "runAfter": {},
                                                "type": "ApiConnection"
                                            },
                                            "Post_a_tweet": {
                                                "inputs": {
                                                    "body": "@body('Get_attachment_content')",
                                                    "host": {
                                                        "connection": {
                                                            "name": "@parameters('$connections')['twitter']['connectionId']"
                                                        }
                                                    },
                                                    "method": "post",
                                                    "path": "/posttweet",
                                                    "queries": {
                                                        "tweetText": "@{items('Apply_to_each')?['TweetText']}  @{items('Apply_to_each')?['Hashtags']}"
                                                    }
                                                },
                                                "metadata": {
                                                    "flowSystemMetadata": {
                                                        "swaggerOperationId": "Tweet"
                                                    }
                                                },
                                                "runAfter": {
                                                    "Get_attachment_content": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "ApiConnection"
                                            },
                                            "Update_item": {
                                                "inputs": {
                                                    "body": {
                                                        "Hashtags": "@items('Apply_to_each')?['Hashtags']",
                                                        "Sent": true,
                                                        "Title": "@items('Apply_to_each')?['Title']",
                                                        "TweetText": "@items('Apply_to_each')?['TweetText']",
                                                        "When": "@items('Apply_to_each')?['When']"
                                                    },
                                                    "host": {
                                                        "connection": {
                                                            "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                                                        }
                                                    },
                                                    "method": "patch",
                                                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('YOUR URL'))}/tables/@{encodeURIComponent(encodeURIComponent('YOUR UID'))}/items/@{encodeURIComponent(items('Apply_to_each')?['ID'])}"
                                                },
                                                "metadata": {
                                                    "flowSystemMetadata": {
                                                        "swaggerOperationId": "PatchItem"
                                                    }
                                                },
                                                "runAfter": {
                                                    "Post_a_tweet": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "ApiConnection"
                                            }
                                        },
                                        "foreach": "@body('Get_attachments')",
                                        "runAfter": {
                                            "Get_attachments": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Foreach"
                                    },
                                    "Get_attachments": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                                                }
                                            },
                                            "method": "get",
                                            "path": "/datasets/@{encodeURIComponent(encodeURIComponent('YOUR URL'))}/tables/@{encodeURIComponent(encodeURIComponent('YOUR UID'))}/items/@{encodeURIComponent(encodeURIComponent(items('Apply_to_each')?['ID']))}/attachments"
                                        },
                                        "metadata": {
                                            "flowSystemMetadata": {
                                                "swaggerOperationId": "GetItemAttachments"
                                            }
                                        },
                                        "runAfter": {},
                                        "type": "ApiConnection"
                                    }
                                },
                                "expression": "@lessOrEquals(items('Apply_to_each')?['When'], utcNow())",
                                "runAfter": {},
                                "type": "If"
                            }
                        },
                        "expression": "@equals(items('Apply_to_each')?['Sent'], bool(false))",
                        "runAfter": {},
                        "type": "If"
                    }
                },
                "foreach": "@body('Get_items')?['value']",
                "runAfter": {
                    "Get_items": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Get_items": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['sharepointonline']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('YOUR URL'))}/tables/@{encodeURIComponent(encodeURIComponent('YOUR UID'))}/items"
                },
                "metadata": {
                    "flowSystemMetadata": {
                        "swaggerOperationId": "GetItems"
                    }
                },
                "runAfter": {},
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 15,
                    "timeZone": "W. Europe Standard Time"
                },
                "type": "Recurrence"
            }
        }
    }
}

Dieser Post ist auch verfügbar auf: German

Related Posts

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top