Bitly

Bitly

URL Shorteners

URL shortener and link management. Welcome to the Bitly API! If you're looking to create Bitlinks, bundles, or retrieve link-level or user-level analytics programmatically, you've come to the right place. To save and edit links as Bitlinks, check out the /v4/links. If all you're looking to do is create Bitlinks on behalf of a single user or site, you can call the Bitly API's /v4/bitlinks method using your generic oauth token which you can you can generate here by confirming your account password at the bottom of the page.

Visit API

📚 Documentation & Examples

Everything you need to integrate with Bitly

🚀 Quick Start Examples

Bitly Javascript Examplejavascript
// Bitly API Example
const response = await fetch('http://dev.bitly.com/get_started.html', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

Bitly API - Simplify Your Links

Bitly API is a powerful tool that allows you to shorten, customize, and share your links. It offers a wide range of features such as link tracking, analytics, and link cloaking. With Bitly API, you can integrate your links with your apps and websites, automate your link management, and gain insights into your audience's behavior.

Getting Started

To use Bitly API, you need to create an account on dev.bitly.com and retrieve your access token. It will be used to authenticate your requests.

Once you have your access token, you can start using Bitly API. Here's a quick overview of some of the endpoints available.

Shortening Links

To shorten a link, you can use the /v4/shorten endpoint. Here's an example in JavaScript using the fetch() method.

const accessToken = 'YOUR_ACCESS_TOKEN';
const apiUrl = 'https://api-ssl.bitly.com/v4/shorten';

const longUrl = 'https://en.wikipedia.org/wiki/JavaScript';

fetch(apiUrl, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ long_url: longUrl }),
})
.then(response => response.json())
.then(data => console.log(data.link))
.catch(error => console.error(error));

Retrieving Link Metrics

To retrieve the metrics (e.g. clicks, referrers, countries) of a link, you can use the /v4/bitlinks/{bitlink}/clicks endpoint. Here's an example in JavaScript.

const accessToken = 'YOUR_ACCESS_TOKEN';
const apiUrl = 'https://api-ssl.bitly.com/v4/bitlinks';

const bitlink = 'bit.ly/3E4vf34';

fetch(`${apiUrl}/${bitlink}/clicks`, {
  headers: {
    'Authorization': `Bearer ${accessToken}`,
  },
})
.then(response => response.json())
.then(data => {
  data.link_clicks.forEach(click => {
    console.log(click.created_at, click.country, click.referrers);
  })
})
.catch(error => console.error(error));

Customizing Links

To customize the slug (i.e. the last part of the short URL) of a link, you can use the /v4/custom_bitlinks endpoint. Here's an example in JavaScript.

const accessToken = 'YOUR_ACCESS_TOKEN';
const apiUrl = 'https://api-ssl.bitly.com/v4/custom_bitlinks';

const longUrl = 'https://en.wikipedia.org/wiki/JavaScript';
const customSlug = 'js-wiki';

fetch(apiUrl, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${accessToken}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    long_url: longUrl,
    domain: 'bit.ly',
    custom_bitlink: customSlug,
  }),
})
.then(response => response.json())
.then(data => console.log(data.link))
.catch(error => console.error(error));

Conclusion

In this blog post, we covered a few examples of using Bitly API in JavaScript to shorten, customize, and retrieve link metrics. Bitly API offers many more endpoints and features that you can explore to simplify your links and improve your user experience. Happy coding!

📊 30-Day Uptime History

Daily uptime tracking showing online vs offline minutes

Jun 2Jun 4Jun 6Jun 8Jun 10Jun 12Jun 14Jun 16Jun 18Jun 20Jun 22Jun 24Jun 26Jun 28Jul 104008001440Minutes
Online
Offline

Related APIs in URL Shorteners