Rebrand your first link

How to rebrand your first link with API

Prerequisites

  • You have already created a Rebrandly account
    If you have not, please read the Signup to Rebrandly guide.

  • You already have an API KEY to authenticate your API requests
    If you don't know how to authenticate your API requests, please read the Authentication guide documentation

  • You understood what a branded short link is and how it is represented as an API
    If you have not, please read Branded short link model

  • You understood what a branded domain is and how it is related to a branded short link
    If you have not, please read Branded domain model

Creating a new branded short link

In order to create a new Link entity, you should first decide what content to rebrand and how you want the final branded short link to look like.

Quick example of rebranding a link with the 'rebrand.ly' default domain: every account can use the 'rebrand.ly' default.
Let's say we want to shorten https://www.wired.com/2016/07/ferrari-laferrari-spider-convertible-photos-specs/ to become http://rebrand.ly/burn10M.

Well, the domain id of rebrand.ly is 8f104cc5b6ee4a4ba7897b06ac2ddcfb, but since rebrand.ly is the default domain for every Rebrandly account, we can choose to not specify the domain while creating a new link. This is up to the user.

📘

Where do I get that branded domain "id"?

Every time you add a new branded domain in Rebrandly, it is associated with a unique identifier. If you want to create a link with your own custom branded domain, instead of the default rebrand.ly domain, you should list your domains in order to get each domain's id.

Correspondent Link object is:

{
  "title": "How to burn 10M",
  "slashtag": "burn10M",
	"destination": "https://www.wired.com/2016/07/ferrari-laferrari-spider-convertible-photos-specs/",
  "domain": {
    "id": "8f104cc5b6ee4a4ba7897b06ac2ddcfb"
  }
}

🚧

Test with a different slashtag!

NOTE: for your personal tests, you should choose another slashtag, because the one used for this demo is already used.

Now we have to send our Link entity to Rebrandly API.
The endpoint to do this is /links (see how to create a new link).
An HTTP POST request to https://api.rebrandly.com/v1/links will create the link:

curl \
  -H 'apikey: YOUR_API_KEY' \
  -H "Content-Type: application/json" \
  -X POST -d '
  {
  	"slashtag":"burn10M",
    "title":"How to burn 10M",
    "domain": {	
    	"id":"8f104cc5b6ee4a4ba7897b06ac2ddcfb"
    },
    "destination":"https://www.wired.com/2016/07/ferrari-laferrari-spider-convertible-photos-specs/"
  }' \
  'https://api.rebrandly.com/v1/links'

Or, without the domain part (because the domain is rebrand.ly, the default domain):

curl 
  -H 'apikey: YOUR_API_KEY' \
  -H "Content-Type: application/json" \
  -X POST -d \
  '{
  	"slashtag":"burn10M",
    "title":"How to burn 10M",
    "destination":"https://www.wired.com/2016/07/ferrari-laferrari-spider-convertible-photos-specs/"
    }' \
  'https://api.rebrandly.com/v1/links'

If everything works properly, you will get back the Link entity you just created:

{
    "id": "ffs24cc5b6ee4a5gh7897b06ac2d16d4",
    "title": "The LaFerrari Supercar Convertible Is the New Best Way to Burn $1M | WIRED",
    "slashtag": "burn10M",
    "destination": "https://www.wired.com/2016/07/ferrari-laferrari-spider-convertible-photos-specs/",
    "createdAt": "2016-07-13T10:54:12.000Z",
    "updatedAt": "2016-07-13T10:54:12.000Z",
    "shortUrl": "rebrand.ly/burn10M",
    "domain": {
      "id": "8f104cc5b6ee4a4ba7897b06ac2ddcfb",
      "ref": "/domains/8f104cc5b6ee4a4ba7897b06ac2ddcfb",
      "fullName": "rebrand.ly"
    },
    ...
  }

Testing your branded short link

Just click on http://rebrand.ly/burn10M to test it: you should be redirected to the destination url within milliseconds.
Weird, right?