How to Use Ninox Formula to Shorten URLs: Write a Ninox Script to Call APIs

How to Use Ninox Formula to Shorten URLs: Write a Ninox Script to Call APIs

Updated on Jun 18, 2024, 10:10 AM

Step 1: Create Your U301 API Key

Head over to your U301 dashboard and create your API key by navigating to "Settings > API Key."
Go to https://u301.com/dashboard/settings/api-key

Fill in the note and key expiration days, then create your key. It will start with the prefix "oat_".

Step 2: Create a Table with Two Columns

Set up a new table with the following columns:

  • Original URL
  • Shortened URL

Their type should be "URL".

Step 3: Create a Formula in the Original URL Field

  1. Edit the fields in your table.
  2. Click on the "Original URL" field, and expand the "More options" field.
  3. Click on the fx button in the end of "Trigger after update" field.
  4. Switch from "Visual" to "Text" in the top right corner and write the following Ninox script in the editor:
'Shortened URL' := (
    let response := do as server
        http("GET", "https://api.u301.com/v2/shorten?url=" + urlEncode('Original URL'), {
            Authorization: "Bearer REPLACE_YOUR_API_KEY_HERE"
        }, null)
    end;
    if response.error then
        alert(text(response.error))
    else
        text(response.result.shortened)
    end
)

Remember to replace "REPLACE_YOUR_API_KEY_HERE" with your generated U301 API key.

  1. Click the "Save" button.
  2. Click "OK" to save the table.

Step 4: Test Your Formula

Now, every time you input an original URL in the "Original URL" field, you'll see the shortened URL in the "Shortened URL" field 🎉.

References