Bitly API — How to Create a Shortened link with Bitly API V4

Samuel Ezedi
5 min readJul 1, 2020

For some of us that have tried to integrate Bitly API for the first time, we always have something in common, which is how frustrating it is at first. I remember spending so much time trying to figure out how it’s done. In this article, I will be sharing with you how to create a shortened link with Bitly API V4.

Note: There will be lots of images in the article to assist you where you miss a step.

Let’s begin

The first step would be to get our Generic Access token. This will facilitate our requests in acquiring a shortened URL with Postman.

Please download Postman if you do not have it installed on your computer, Postman is a software development tool. It enables people to test calls to APIs.

Here’s a link to Bitly API Documentation

Step 1: How to Generate an Access Token,

To generate a generic access token, you will have to make sure you are logged into your Bitly account. If so, click the rectangular box that has your name:

Then click Profile Settings

A sidebar will pop out with some options, select Generate Access Token

Now you’ll be required to enter your password, after which you then click generate token.

This will generate an access token for you, please copy.

Step 2: How to retrieve Group_Guid:

Now that we have our access token we will use it to retrieve our group_guid, head over to Postman. We will make a GET request to https://api-ssl.bitly.com/v4/groups in order to retrieve our group_guid, make sure to input the Access token generated in Headers Authorization field, if it's not there, simply add it, here’s an example below:

Once this is done click Send. You should get this below as response:

Step 3: Retreive client_id and client_secret

To retrieve your client_id and client_secret, open bitly (make sure to be logged in) and click your name on the top right corner:

Then click Profile Settings

Then click Register OAuth Applications

A sidebar will pop out with a Button Register New App, click the button and an email will be sent to your registered Bitly email. Open the email and click Complete Registration

Now this will open Bitly with a sidebar popped out. Fill the form in the sidebar and click Register App. Once it’s registered you will get a success message saying your app has been added. Then click on the App you just added and you’ll see your client_id and client_secret.

Step 4: Generate OAuth2 Access token

To do this, you’ll open the Bitly Documentation, on the side menu, under the Authentication Tap, click “Exchanging a Username and Password for Access Tokens”,

Then scroll a bit and copy the curl command same as the one on this image

Now open your Postman, create a new Tab, paste this link in the URL field https://api-ssl.bitly.com/oauth/access_token.

Now click Import at the top right corner of the Postman window

Click Raw Text

Now paste the curl command you copied in here and replace username with your Bitly username or email and password with your Bitly password, then click Continue and click Import.

Once you do this, click on the Authorization tab, replace the username with your client_id and password with client_secret:

Your header needs no changes, the body will need group_type with the word password as its value, the username will be your Bitly username (email) and password will be your Bitly password.

Then click Send and you will receive your access token as a response.

Step 5: Shorten a URL.

Now you have your group_guid and access tokens. create a new tab in postman and make a post request with this URL https://api-ssl.bitly.com/v4/shorten. Your header should contain the following

Host: api-ssl.bitly.com

Content-Type: application/json

Authorization: Your Access token from step 4

The Body should contain JSON data like this;

{"long_url": "https://play.google.com/store/apps/details?id=net.cubiclab.pronoun&showAllReviews=truem","group_guid": "Bi3vl5dhjVW"}

Look close at the images below to avoid confusion

Click Send.

You should get a response like this with your shortened link data.

That’s it for this article! I hope you enjoyed it, and be sure to follow me for more articles and comment for any feedback you might have about this article.

--

--

Samuel Ezedi
Samuel Ezedi

No responses yet