Description
This Apps Script function allows you to automatically shorten URLs in a Google Sheet using the Cuttly API. By setting up an installable trigger, the function will run automatically whenever a long URL is entered in the specified column, making it easier to manage and share shortened URLs.
Instructions
Create a Google Sheet:
Name the sheet (e.g., Sheet1
).
Populate the sheet with long URLs in the specified column (e.g., column A).
Get a Cuttly Access Token.
Sign up for a Cuttly account if you don't have one at https://cutt.ly/.
After signing up, confirm the activation link sent to your email. Log in, navigate to the "Edit Account" page, and generate an API key from the "Manage API" section.
Note: If you previously used Bitly, you can sign up for a Bitly account at https://bitly.com/ for an alternative service.
Add the Script:
Open your Google Sheet.
Go to Extensions > Apps Script
.
Delete any code in the script editor and replace it with the script provided below.
Update the Script:
Replace "Sheet1"
with the name of your sheet if different.
Adjust the urlColumn
variable to match the column number of the URLs you want to shorten (1-based index).
Replace "YOUR_CUTTLY_API_KEY"
with your Cuttly API key.
Set Up an Installable Trigger:
In the Apps Script editor, click on the clock icon to open the triggers page.
Click on + Add Trigger
at the bottom right.
Choose shortenUrls
function.
Set the event type to On edit
.
Save the trigger.
Now, whenever you enter a long URL in the specified column (e.g., column A), the script will automatically shorten the URL without needing to manually run the function.
No comments:
Post a Comment