Skip to content

Simplifying Social Media Sharing with Azure Logic Apps and iOS Shortcuts

Published: | 8 min read

Table of contents

Open Table of contents

Intro

I am quite active on Twitter, and it feels like a natural platform for me. On the other hand, I would like to have more active presence on LinkedIn too, but I just seem to forget to post on there too. So, let’s make this a bit easier for me!

While I write this in quite in detail and step by step, I will not go into details how to get started with Azure, Azure Logic Apps or iOS Shortcuts.

Prerequisites

Azure Logic Apps

Azure Logic Apps is a low-code option to build simple “data flow apps”. Microsoft itself describes Logic Apps as so:

Connect your business-critical apps and services with Azure Logic Apps, automating your workflows without writing a single line of code.

I will not fall in to the trap of discussing whether or not low-code is the future of app development or the right choice, or a complete lie. As far as my own experience goes, low-code most definitely is not there yet for complex apps. Then again, it has its use cases, this example here being one. No point to start coding an app, when all the necessary actions are available out of the box, at a very small cost.

Azure Logic Apps are billed by the action execution, so this is something to keep in mind when designing and developing these low-code apps. Especially if you use loops, pay special attention to this, or it could bite the bill payer :)

Azure Logic App: Social Poster

Azure Logic Apps are handy in the way, that you get a logic diagram for “free”, since that is the implementation of the whole app. In all its complexity, my Social Poster app looks like this:

LA overview

Let’s break this down:

  1. When an HTTP request is received: This flow is triggered by an HTTP POST request, with a specific JSON payload.
  2. Post a tweet: Post a tweet :)
  3. Share an article V2: Share an article on LinkedIn :) :)

HTTP Trigger and payload design

The design of the json payload is entirely in my hands, but is dependent of the information the following actions require. When inspecting the connectors, the Twitter connectors needs only one part of information, the tweet text itself.

LinkedIn on the other hand needs multiple peaces of information:

This basically dictates, that my JSON payload needs to have these three attributes. So, this is the design I did:

{
    "title": "Test Title: From Pelican to Gatsby, and why?",
    "text": "Test Text: This blog of mine has been a static site for almost its full lifetime. #blogging #Gatsby",
    "post_url": "https://janik6n.net/from-pelican-to-gatsby-and-why"
}

In order to be able to use the data in the JSON payload in the Logic App actions, I need to define the JSON schema. This is easiest done by hitting the Use sample payload to generate schema on the HTTP trigger action, and pasting a sample message to the dialog box.

Logic App HTTP trigger

The Logic Apps public URL is generated, when you save the Logic App for the first time.

Note on authentication: Azure Logic Apps uses the concept of Shared Access Keys, which are presented as SAS URLs. This is what you get, when the Logic App is saved for the first time. In other words: Anyone having the complete SAS URL will be able to successfully call your Logic App flow. Please do not share the URL with anyone, who should not have it! If you need to regenerate the SAS URL (key part), you can easily do so in the Logic App’s Settings, under Access keys.

Post a tweet Action

When the Post a tweet action is added to the Logic App, you will need to sign in with the standard Twitter OAuth2 flow. The login info gets stored in Azure’s API Connections section, and are shared within the Subscription and Region, so the same API connection can be used in multiple Logic Apps.

Logic App Twitter action

As the picture above describes, posting a tweet is as simple as composing the tweet message with the variables and static text. The Logic App helpfully parsed the variables out of the JSON based on the schema definition I created earlier.

Please keep in mind the maximum length of the tweet, which is 280 characters at the time of writing! The calculation of the character length is not as straightforward as it may seem. Please have a look at the links in the end of this article. My Logic App assumes, that the client calling this flow will take care of the user input validation.

In addition, the Logic App Twitter connector has some quite strict limitation on top of this, for example you cannot @ mention anyone, and these characters will be removed altogether. Please have a look at the links below for detailed info.

Share an LinkedIn article

When the Share an article V2 action is added to the Logic App, you will need to sign in with the standard LinkedIn OAuth2 flow.

Logic App LinkedIn action

The LinkedIn action is more complicated compared to the Twitter one above. The action requires us to enter multiple parameters (which you can by the way add with the Add new parameter dropdown).

The parameters available for this action are not very clear. For example what is the difference between Title and Subject? I have no idea.

By testing the various combinations, I come to a conclusion, that the fields Content URL, Title and Text are the correct ones to use, as pictured above.

Testing the Logic App

I could use any HTTP Client out there to issue a test request to my new Logic App’s HTTP endpoint. Simply:

  1. Send a HTTP POST request to the Logic App’s URL.
  2. Remember to set header Content-Type to application/json.
  3. Enter body as described earlier in this article.

After successful submission, the results can be seen in Azure portal (more details can be seen by expanding each action): Logic App execution visual log

… And on Twitter: Twitter tweet

… And on LinkedIn: LinkedIn article

Nice. Now I just need to build the iOS / iPadOS Shortcut which calls this Logic App. Let’s do that next!

iPhone / iPad Shortcut

Shortcuts are fantastic way to automate things on the mobile. They work on both iOS (iPhone) and iPadOS (iPad) and are shared between your Apple account through iCloud. You only need to build the shortcut once, and you can use it on all of your devices.

One could think of Logic Apps on the Azure cloud to be a very close analogy to Shortcuts on Apple’s mobile ecosystem.

The full Shortcut is below as a picture, and I highlighted each section with red rectangle and a number. Each section is then described below.

Shortcut full

1. Share Sheet input

This Shortcut is meant to be run from Share Sheet and it expects to get an URL as the data format. After creating the Shortcut, remember to check these settings by hitting the three-dot button on the Shortcut title: Shortcut settings

2. Ask for Title and Text

Ask text input for the post Title, and Text. Possible hashtags go within the text. I use variables here, which come handy in the next validation and “retry” section.

3. Validate user input

Validate the input. Mainly at this point I am concerned with the text length, which must be within the Twitter API/action rules. Based on the documentation linked in Further reading:

As I showed earlier, I format the tweet like so:
[Title]

[Text] [URL]

With the new lines and blanks, let's do the math:

280 (Tweet character limit is 280)
-
23 (1 URL, each URL is 23 characters long)
-
2 (2 new lines)
-
1 (1 blank between Text and URL)
= 254

So we have 254 characters to be used in Title and Text combined.

For these kinds of data manipulation / retry actions Shortcuts is quite limited and awkward to work with.

4. Post the message to the Logic App

First I create the JSON payload as a text by using the variables set earlier in the Shortcut.

I use an app called Data Jar to store API URLs, API keys, and pretty much all parameter data used in my Shortcuts. Data Jar makes it easy to reuse data between Shortcuts. In this action I read the nested value from Data Jar.

I am doing an HTTP POST request to the Logic App’s URL endpoint. I set the Content-Type header to application/json, and provide the JSON body as File. Do not ask me, why Shortcuts requires this, just do it :)

Then I simply catch the API call response and show it. This could be made more user friendly by parsing the response and showing a nice message for succesful posting, or an error message for less succesful ones.

Recap

In this article I showed how you can utilize Azure’s low-code tools to help automate social media posting, and trigger these automations from Apple’s mobile devices. Logic Apps and Shortcuts can be used for much much more, hopefully this article gave you one real-life example how they can be used.

Fun trivia: Writing this article took 4 times as long, as the solution itself :)

Further reading