SDKs overview

Rebrandly offers Software Development Kits (SDKs) and libraries designed to facilitate interaction with its API for creating, managing, and tracking branded links. These tools encapsulate the underlying HTTP requests and authentication mechanisms, allowing developers to integrate Rebrandly's functionality into their applications using native language constructs rather than direct API calls. SDKs typically handle tasks such as request formatting, response parsing, and error handling, which can reduce development time and potential integration errors.

The core functionality exposed through Rebrandly's SDKs and libraries includes operations to shorten URLs, assign custom domains, retrieve link analytics, and manage workspaces and teams programmatically. This enables developers to embed branded link capabilities directly into content management systems, marketing automation platforms, or custom applications. Authentication for all API interactions, whether direct or via an SDK, relies on an API key, which must be included in requests to authorize access to a user's Rebrandly account Rebrandly API Key management.

Rebrandly's API is built on REST principles, utilizing standard HTTP methods (GET, POST, PUT, DELETE) and JSON for data exchange. This architectural style ensures that the API is stateless and can be consumed by a wide range of clients, making it suitable for integration across diverse programming environments W3C REST architectural style. The SDKs are designed to abstract these RESTful interactions, providing idiomatic interfaces for each supported language.

Official SDKs by language

Rebrandly provides official SDKs for several popular programming languages, designed to offer a streamlined development experience. These SDKs are maintained by Rebrandly and are typically the recommended method for integrating with the API due to their direct support and alignment with API updates. The official SDKs cover a range of use cases from basic link shortening to advanced link management and analytics retrieval.

Below is a table summarizing the official SDKs, their typical package names, and installation commands:

Language Package/Repository Install Command Maturity
JavaScript (Node.js) rebrandly-api npm install rebrandly-api Stable
Python rebrandly pip install rebrandly Stable
Ruby rebrandly-ruby gem install rebrandly-ruby Stable
PHP rebrandly/rebrandly-php composer require rebrandly/rebrandly-php Stable
Go github.com/rebrandly/rebrandly-go go get github.com/rebrandly/rebrandly-go Stable

Each official SDK typically mirrors the structure of the Rebrandly API, offering methods corresponding to API endpoints for domains, links, tags, and other resources Rebrandly API Reference documentation. Developers can find detailed documentation and examples for each SDK within the Rebrandly developer portal, which includes usage instructions and parameter definitions.

Installation

Installing Rebrandly SDKs typically involves using the package manager specific to the programming language. The following sections provide common installation steps for the officially supported SDKs.

JavaScript (Node.js)

For Node.js environments, the Rebrandly SDK can be installed via npm, the default package manager for JavaScript.

npm install rebrandly-api

After installation, the package can be imported into your JavaScript files using require or import statements.

Python

Python developers can install the Rebrandly SDK using pip, Python's package installer.

pip install rebrandly

Once installed, the library can be imported into Python scripts for use.

Ruby

Ruby users can install the Rebrandly gem via the RubyGems package manager.

gem install rebrandly-ruby

The gem can then be required in Ruby applications.

PHP

PHP projects typically use Composer for dependency management. The Rebrandly PHP SDK can be added to a project with the following command:

composer require rebrandly/rebrandly-php

This will add the SDK to your project's vendor directory and make it available through Composer's autoloader.

Go

For Go projects, the SDK can be fetched using the go get command.

go get github.com/rebrandly/rebrandly-go

After fetching, the package can be imported into your Go source files.

Quickstart example

This quickstart example demonstrates how to use the Rebrandly Python SDK to create a new branded short link. This process typically involves initializing the SDK with an API key and then calling a method to create a link with specified parameters, such as the original URL and a custom domain.

Before running this code, ensure you have installed the Python SDK using pip install rebrandly and replaced YOUR_REBRANDLY_API_KEY with your actual API key.

import rebrandly

# Replace with your actual Rebrandly API key
API_KEY = "YOUR_REBRANDLY_API_KEY"

# Initialize the Rebrandly client
rebrandly.api_key = API_KEY

def create_branded_link(destination_url, domain_id=None, slashtag=None):
    """
    Creates a new branded short link using the Rebrandly API.
    """
    try:
        link_data = {
            "destination": destination_url
        }
        if domain_id:
            link_data["domain"] = {"id": domain_id}
        if slashtag:
            link_data["slashtag"] = slashtag

        new_link = rebrandly.Link.create(**link_data)
        print(f"Successfully created link: {new_link.shortUrl}")
        print(f"Original URL: {new_link.destination}")
        print(f"ID: {new_link.id}")
        return new_link
    except rebrandly.exceptions.RebrandlyException as e:
        print(f"Error creating link: {e}")
        return None

# Example Usage:
# To create a link with a default domain:
# created_link = create_branded_link("https://www.example.com/long-page-path")

# To create a link with a specific domain and slashtag (replace with your actual domain ID and desired slashtag)
# You need to retrieve your domain ID from the Rebrandly dashboard or API.
# Example domain ID and slashtag (these are placeholders):
# DOMAIN_ID_EXAMPLE = "YOUR_DOMAIN_ID_HERE" # e.g., 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'
# SLASHTAG_EXAMPLE = "my-custom-path"

# created_link_custom = create_branded_link(
#     "https://www.another-example.com/very-long-article",
#     domain_id=DOMAIN_ID_EXAMPLE,
#     slashtag=SLASHTAG_EXAMPLE
# )

print("Please uncomment and replace placeholders with your actual API key, domain ID, and URLs to run the example.")

This example initializes the Rebrandly client with an API key and then calls the Link.create method with the target URL. For creating links with custom domains or specific slashtags, additional parameters would be passed to the create method. Developers should consult the official Rebrandly Python SDK documentation for a complete list of available parameters and methods.

Community libraries

Beyond the officially supported SDKs, the Rebrandly API has inspired the development of various community-contributed libraries and connectors. These libraries are often developed by individual developers or third-party integrators to meet specific needs or to provide wrappers for languages not officially supported by Rebrandly. While not directly maintained by Rebrandly, community libraries can offer alternative implementations, specialized functionalities, or integrations with other platforms.

When considering community-developed libraries, it is important to evaluate their maintenance status, community support, and alignment with the latest Rebrandly API versions. Resources like GitHub and package repositories (e.g., npm, PyPI, Packagist) are common places to discover such libraries. Developers should review the source code, issue trackers, and usage examples to ensure the library meets their project requirements and security standards. Compatibility with the current API version is a critical factor, as API updates can sometimes introduce breaking changes that community libraries may not immediately incorporate Mozilla API versioning best practices.

Examples of community contributions might include:

  • WordPress Plugins: Integrations that allow WordPress users to automatically generate branded links when publishing content.
  • CLI Tools: Command-line interfaces built on top of the Rebrandly API for quick link management from the terminal.
  • Frontend Libraries: JavaScript libraries designed for client-side applications to interact with Rebrandly API, potentially with UI components.
  • Specific Language Wrappers: Libraries for languages like C#, Java, or others where an official SDK might not be available, but community members have created wrappers.

Developers are encouraged to check the Rebrandly developer community forums or GitHub for the most up-to-date information on community-supported projects. Always verify the authenticity and security of third-party libraries before integrating them into production environments.