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.

Leave a Reply