How to Use the URLShortly API for Link Shortening – Step-by-Step Guide

May 13, 2025
smith
smith
smith
smith
7 mins read

If you're looking to automate your link shortening process or integrate short link creation into your web or mobile application, the URLShortly API is a powerful tool. In this article, we'll walk you through how to use the API effectively to shorten URLs in real time.


Step 1: Generate Your API Key

To get started, you need access to the URLShortly API. Here’s how you can generate your API key:

  1. Log in to your URLShortly admin dashboard.
  2. Go to the API or Developer Tools section.
  3. Click on Generate API Key.
  4. Copy and securely store your API key. (You’ll need it for all requests.)

Step 2: API Endpoint Overview

The basic endpoint for shortening a URL usually looks like this:

POST https://urlshortly.com/api/shorten

Required Headers:

{
  "Authorization": "Bearer YOUR_API_KEY",
  "Content-Type": "application/json"
}

Request Body:

{
  "long_url": "https://example.com/page",
  "custom_slug": "optional-custom-slug"
}

Step 3: Sample API Request in cURL

curl -X POST https://urlshortly.com/api/shorten \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
  "long_url": "https://example.com/page"
}'

Step 4: Understanding the Response

If your request is successful, you’ll receive a JSON response like:

{
  "status": "success",
  "short_url": "https://urlshortly.com/xyz123",
  "slug": "xyz123"
}

You can now use the short_url in your app, emails, social media, or anywhere else.


Step 5: Handling Errors

Here are common error responses:

  • 401 Unauthorized – Invalid or missing API key.
  • 400 Bad Request – Missing required fields like long_url.
  • 409 Conflict – Custom slug already in use.

Always check the status code and message in the response for debugging.


Step 6: Best Practices

  • Don’t expose your API key in frontend code.
  • Log errors for debugging purposes.
  • Use HTTPS to secure API communications.
  • Rate-limit requests to avoid abuse or API throttling.

Conclusion

Using the URLShortly API can streamline your link management process, especially if you’re working with bulk links or automated workflows. With just a few lines of code, you can start generating short URLs and tracking them effectively.

Ready to build something cool? Stay tuned for the next guide on “How to Generate Bulk Short Links Using URLShortly.”


 

Keep reading

More posts from our blog

Create Custom Short Links for Branding with URLShortly
By smith May 13, 2025
In today’s digital marketing world, branding is everything. From logo designs to color schemes, your brand’s identity needs to be reflected in...
Read more
Efficient Link Management for Marketing Campaigns with URLShortly
By smith May 13, 2025
Effective link management plays a crucial role in optimizing marketing campaigns. Whether you’re running an email campaign, social media ads, or a...
Read more
How to Track and Manage Bulk Links on URLShortly – Complete Guide
By smith May 13, 2025
Managing bulk links can be a challenging task, especially when you're dealing with hundreds or thousands of URLs. However, with URLShortly, you can...
Read more