Get a short URL from YOURLS in Zapier

With the incredible Code by Zapier app, getting a short URL for any URL you have is very easy using the API in YOURLS. I used this strategy to promote new content from my websites on social media using the item’s short URL.

I love automating things. For a few years now I’ve configured my site using Jetpack’s Publicize module in conjunction with Buffer to automatically post new content to my social networks. However, there’s a couple of limitations with that approach:

  1. Publicize seemingly won’t let you use the post’s short URL,
  2. You have little control over when these posts go out on social media.

With my new found love of Zapier, I sought to rectify both of these issues.

First up: getting a YOURLS short URL for a post in Zapier. You can do this using the relatively new Code by Zapier app. This app allows you to run Python or JS to perform calculations, or modify or retrieve data.

I sought to leverage YOURLS’ API, whereby you can make HTTP requests to your YOURLS installation to get short URLs for any URL you provide.

My general process is to check an RSS feed for new entries (I didn’t feel comfortable providing a username and password to Zapier for my WordPress install in order to the use the WordPress app) and then to take the item URL from the RSS feed and send it to YOURLS to give me a short URL back (if a short URL exists it simply returns it: otherwise it creates one and returns it).

Item 1 in my zap is the RSS feed check. Item 2 is the Python code. Here’s what the code generally looks like where article_url is an input created from the item link in Step 1:

When you run that, you should now have a short URL available to you for use in subsequent steps in your zap.

I then used this in conjunction with the Delay app to create new social posts on a set schedule using my short URL from YOURLS.

Seriously, I can’t get enough of Zapier right now…

Author: Dave

Dave is many things. Most importantly, he's a husband and a father to Ellie and Jack. Almost as important, he's British (though he lives in Florida). Following on from there, he's a WordPress developer and civil engineer, has an unhealthy love of hummus, is vegan, likes cider, wants to travel to Iceland and Japan, loves solving puzzles and is a realist.

2 thoughts on “Get a short URL from YOURLS in Zapier”

  1. Hi,

    Do you think you could also make this work for Airtable? What I wish to do is use Airtable to keep all my campaigns together and once a new value has been added to my airtable field “campaign link” let it shorten automatically and also push back the link to the same row field “short link”.

    Please let me know if you could help with this/ give some tips

  2. That’s awesome! Thank you for sharing this. I took a different approach. I created a zap with one trigger and two actions. Once I post a picture on Instagram, the first action is to call the python code and generate the short URL, and the second action is to post on twitter using the instagram outputs from step 1 and the short_url from step 2. It works like a charm. I’ve tried to do this with IFTTT, but you can only call one action, and I had to mess with YOURLS plugins. I was able to make it work, but it would stop working out of nowhere.

Leave a Reply