How can I create TinyURL links using Google Sheets?

You can integrate the TinyURL API with Google Sheets using Apps Script and an API token. Follow these instructions to set it up:

  1. Register and set up your account: Create a TinyURL account if you don't have one. Then, generate an API token with "Create TinyURL" permissions and store it in a secure location.
  2. Open your Google Sheet: Navigate to the Google Sheet where you want to generate TinyURLs from destination URLs.
  3. Access Apps Script: Go to Extensions > Apps Script. A new window will open.
  4. Add the script: Copy the provided script into the editor window. On line 3, replace yourTokenValue with the API token from step 1 (e.g., var token = "abc123yourActualToken";).
  5. Prepare your data: Enter a destination URL in a cell, such as J6.
  6. Generate TinyURLs: In another cell (e.g., K6), enter the formula =shortenUrl(J6) to automatically create a TinyURL. Drag the formula down to apply it to additional URLs.
function shortenUrl(longUrl) {
  var apiUrl = "https://api.tinyurl.com/create";
  var token = "yourTokenValue"; // replace with your real token

  var payload = {
    "url": longUrl
  };

  var options = {
    method: "post",
    headers: {
      "Authorization": "Bearer " + token,
      "Accept": "application/json",
      "Content-Type": "application/json"
    },
    payload: JSON.stringify(payload),
    muteHttpExceptions: true
  };

  var response = UrlFetchApp.fetch(apiUrl, options);
  var json = JSON.parse(response.getContentText());

  // TinyURL API returns { data: { tiny_url: "..." } }
  if (json.data && json.data.tiny_url) {
    return json.data.tiny_url;
  } else {
    return "Error: " + response.getContentText();
  }
}

Please enter a valid email address.

Signup for a TinyURL premium account

Unlock access to full analytics to your TinyURLs, use your own branded domain, and more.

View Details

Create an Account

Create an account to enjoy easy link shortening, customized TinyURLs, and full shortened URL history.

Sign Up