How to regenerate a bitly link for the same long URL?

A small hack to always get a unique bitly link. Check it out.

How to regenerate a bitly link for the same long URL?

A Bitly link is generated on setting multiple parameters. If your long URL remains the same, the bitly link generated will be the same as before. Also, a bitly link cannot expire so there is no question of regeneration.

But there is a small hack to fix this...

In URL, simply add another query params that keeps changing. Set current time in your query params as it keeps changing and will provide you a unique link every time you generate. You don't have to keep a counter increasing to do this. As Simple As That.

Example:

Long URL - rahulchouhan.hashnode.dev + ?date=new Date() Script -

// Angular Code
// long_url = "https://rahulchouhan.hashnode.dev/"
shortenUrl(long_url: string) {
    let routeUrl = "https://api-ssl.bitly.com/v4/shorten";
    let headers = new HttpHeaders({
              Authorization: 'Bearer YOUR-BITLY-TOKEN'
    });

    // Adding date factor so as to generate unique URLs all time
    long_url += "&date=" + new Date();

    return this.http.post(routeUrl, { long_url }, { headers });
}

AND WE ARE DONE! 🎉