Python SDK Documentation

Links Class

The Links class provides a comprehensive interface for managing URL shortening and related functionality through the Rebrandly API. This class handles all link-related operations including creation, updating, deletion, and management of associated features like deep links, traffic routing, and OpenGraph metadata.

Class Usage

Example:

from rebrandly_official.rebrandly_client import RebrandlyClient

client = RebrandlyClient('YOUR_API_KEY')
links = client.links

# Optionally, set workspace id for the session instead of adding it to each method call individually
client.update_workspace('yourworkspaceid')

Core CRUD Link Operations

Get Link Details

def get(self, link_id, workspace_id=None)

Example:

# Get details of a specific link
link = links.get('yourlinkid', 'yourworkspaceid')

Retrieves details for a specific link.

  • Parameters:
    • link_id: String - The ID of the link to retrieve
    • workspace_id: String (Optional) - The workspace ID to operate in
  • Returns: JSON object containing link details

Create Link

def create(self, destination, slashtag='', title='', domain_id='', domain_name='', description='', workspace_id='')

Example:

# Create a new shortened link
new_link = links.create(
    destination='https://www.rebrandly.com',
    slashtag='rb-home',
    title='Rebrandly Homepage',
    domain_id='yourdomainid',
    description='The #1 platform for branded short links',
    workspace_id='yourworkspaceid'
)

Creates a new shortened link.

  • Parameters:
    • destination: String - The target URL
    • slashtag: String (Optional) - Custom path for the shortened URL
    • title: String (Optional) - Title for the link
    • domain_id: String (Optional) - ID of the domain to use
    • domain_name: String (Optional) - Full name of the domain
    • description: String (Optional) - Description of the link
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the created link details

Update Link

def update(self, link_id, destination, title, favourite='', description='', workspace_id='')

Example:

# Update an existing link
updated_link = links.update(
    'yourlinkid',
    destination='https://www.rebrandly.com',
    title='Updated Title',
    favourite=True,
    description='Updated description',
    workspace_id='yourworkspaceid'
)

Updates an existing link's properties.

  • Parameters:
    • link_id: String - ID of the link to update
    • destination: String - New destination URL
    • title: String - New title
    • favourite: Boolean (Optional) - Favorite status
    • description: String (Optional) - New description
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing updated link details

Delete Link

def delete(self, link_id, workspace_id='')

Example:

# Delete a specific link
deleted_link = links.delete('yourlinkid', 'yourworkspaceid')

Deletes a specific link.

  • Parameters:
    • link_id: String - ID of the link to delete
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the deleted link details

List Links

def list(self, workspace_id='', order_by='', order_dir='', limit='', favourite='', domain_id='', domain_name='', creator_id='', slashtag='', date_from='', date_to='')

Example:

# List links with filtering and ordering
links = links.list(
    workspace_id='yourworkspaceid',
    limit=10,
    favourite=True,
    domain_id='yourdomainid'
)

Retrieves a list of links with optional filtering.

  • Parameters:
    • workspace_id: String (Optional) - Filter by workspace
    • order_by: String (Optional) - Field to order by
    • order_dir: String (Optional) - Order direction
    • limit: Integer (Optional) - Maximum number of results
    • favourite: Boolean (Optional) - Filter by favorite status
    • domain_id: String (Optional) - Filter by domain ID
    • domain_name: String (Optional) - Filter by domain name
    • creator_id: String (Optional) - Filter by creator
    • slashtag: String (Optional) - Filter by slashtag
    • date_from: String (Optional) - Start date for filtering
    • date_to: String (Optional) - End date for filtering
  • Returns: PaginatedResponse object containing list of links

Bulk Operations

Bulk Create Links

def bulk_create(self, workspace_id, links)

Example:

# Create multiple links at once
links_to_create = [
    {
        "destination": "https://example1.com",
        "domain": {"id": "yourdomainid"},
        "slashtag": "link1"
    },
    {
        "destination": "https://example2.com",
        "domain": {"id": "yourdomainid"},
        "slashtag": "link2"
    }
]
created_links = links.bulk_create('yourworkspaceid', links_to_create)

Creates multiple links in a single operation.

  • Parameters:
    • workspace_id: String - Workspace ID
    • links: List - List of link objects to create
  • Returns: JSON object containing created links

Bulk Delete Links

def bulk_delete(self, links, workspace_id='')

Example:

# Delete multiple links at once
link_ids = ['yourlinkid', 'yoursecondlinkid', 'yourthirdlinkid']
deleted_count = links.bulk_delete(link_ids, 'yourworkspaceid')

Deletes multiple links in a single operation.

  • Parameters:
    • links: List - Array of link IDs to delete
    • workspace_id: String (Optional) - Workspace ID
  • Returns: Integer count of deleted links

Link Management

Set Favorite Status

def favourite(self, link_id, favourite, workspace_id='')

Example:

# Mark a link as favorite
favorite_link = links.favourite('yourlinkid', True, 'yourworkspaceid')

# Remove favorite status
unfavorite_link = links.favourite('yourlinkid', False, 'yourworkspaceid')

Sets the favorite status of a link.

  • Parameters:
    • link_id: String - ID of the link
    • favourite: Boolean - Favorite status
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the updated link details

Count Links

def count(self, favourite=None, domain_id='', domain_name='', workspace_id='')

Example:

# Count all favorite links in a workspace
favorite_count = links.count(
    favourite=True,
    domain_id='yourdomainid',
    workspace_id='yourworkspaceid'
)

Counts links matching specified criteria.

  • Parameters:
    • favourite: Boolean (Optional) - Filter by favorite status
    • domain_id: String (Optional) - Filter by domain ID
    • domain_name: String (Optional) - Filter by domain name
    • workspace_id: String (Optional) - Workspace ID
  • Returns: Integer count of matching links

Routing Rules

Create Route

def create_route(self, link_id, route: dict, workspace_id='')

Example:

# Create a routing rule for a link
route_config = {
  "destination":"https://www.rebrandly.com",
  "condition":
    {"and":[{"property":"req.country","operator":"in","values":["ie"]}]}
}
new_route = links.create_route('yourlinkid', route_config, 'yourworkspaceid')

Creates a routing rule for a link.

  • Parameters:
    • link_id: String - ID of the link
    • route: Dict - Route configuration
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the created route details

List Routes

def list_routes(self, link_id, workspace_id='')

Example:

# Get all routes for a link
routes = links.list_routes('yourlinkid', 'yourworkspaceid')

Lists all routes for a link.

  • Parameters:
    • link_id: String - ID of the link
    • workspace_id: String (Optional) - Workspace ID
  • Returns: List of route objects

Update Route

def update_route(self, link_id, route_id, routes, workspace_id='')

Example:

# Update an existing route
updated_route_config = {
  "destination":"https://www.rb.gy",
  "condition":
    {"and":[{"property":"req.country","operator":"in","values":["ie"]}]}
}
updated_route = links.update_route('yourlinkid', 'yourrouteit', updated_route_config, 'yourworkspaceid')

Updates an existing routing rule.

  • Parameters:
    • link_id: String - ID of the link
    • route_id: String - ID of the route to update
    • routes: Dict - Updated route configuration
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the updated route details

Delete Route

def delete_route(self, link_id, route_id, workspace_id='')

Example:

# Delete a specific route
deleted_route = links.delete_route('yourlinkid', 'yourrouteid', 'yourworkspaceid')

Deletes a specific route.

  • Parameters:
    • link_id: String - ID of the link
    • route_id: String - ID of the route to delete
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the deleted route details

Deep Links

Get Apps

def get_apps(self, workspace_id='')

Example:

# Get list of available apps for deep linking
apps = links.get_apps('yourworkspaceid')

Retrieves available apps for deep linking.

  • Parameters:
    • workspace_id: String (Optional) - Workspace ID
  • Returns: List of available apps

List Deep Links

def list_deep_links(self, link_id, workspace_id='')

Example:

# Get all deep links for a specific link
deep_links = links.list_deep_links('yourlinkid', 'yourworkspaceid')

Lists all deep links for a specific link.

  • Parameters:
    • link_id: String - ID of the link
    • workspace_id: String (Optional) - Workspace ID
  • Returns: PaginatedResponse object containing list of deep links

Create Deep Link

def create_deep_link(self, link_id, app_id, path, workspace_id='')

Example:

# Create a deep link for a mobile app
path_config = {
    "path": "/products/123",
    "parameters": {
        "referral": "campaign2024"
    }
}
new_deep_link = links.create_deep_link('yourlinkid', 'yourappid', path_config, 'yourworkspaceid')

Creates a new deep link.

  • Parameters:
    • link_id: String - ID of the link
    • app_id: String - ID of the app
    • path: Dict - Deep link path configuration
    • workspace_id: String (Optional) - Workspace ID
  • Returns: Link Id for link with new deep link configured

Delete Deep Link

def delete_deep_link(self, link_id, app_id, workspace_id='')

Example:

# Delete a specific deep link
deleted_deep_link = links.delete_deep_link('yourlinkid', 'yourappid', 'yourworkspaceid')

Deletes a specific deep link.

  • Parameters:
    • link_id: String - ID of the link
    • app_id: String - ID of the app
    • workspace_id: String (Optional) - Workspace ID
  • Returns: Link Id for link whose deep link was deleted

Delete All Deep Links

def delete_deep_links(self, link_id, workspace_id='')

Example:

# Delete all deep links for a specific link
deleted_count = links.delete_deep_links('yourlinkid', 'yourworkspaceid')

Deletes all deep links for a specific link.

  • Parameters:
    • link_id: String - ID of the link
    • workspace_id: String (Optional) - Workspace ID
  • Returns: Number of deleted deep links

OpenGraph Metadata

Get OpenGraph Data

def get_opengraph(self, link_id, workspace_id='')

Example:

# Get OpenGraph data for a specific link
link_with_opengraph = links.get_opengraph('yourlinkid', 'yourworkspaceid')

Retrieves OpenGraph metadata for a link.

  • Parameters:
    • link_id: String - ID of the link
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the OpenGraph metadata details

Set OpenGraph Data

def set_opengraph(self, link_id, title, description='', image_url='', object_type='', locale='', workspace_id='')

Example:

# Sets OpenGraph data for a specific link
link_with_opengraph = links.set_opengraph('yourlinkid', 'yourtitle', description='yourdescription')

Sets OpenGraph metadata for a link.

  • Parameters:
    • link_id: String - ID of the link
    • title: String - OpenGraph title
    • description: String (Optional) - OpenGraph description
    • image_url: String (Optional) - URL for OpenGraph image
    • object_type: String (Optional) - OpenGraph object type
    • locale: String (Optional) - OpenGraph locale
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the Updated OpenGraph metadata details

Delete OpenGraph Data

def delete_opengraph(self, link_id, workspace_id='')

Example:

# Delete OpenGraph data for a specific link
link_without_opengraph = links.delete_opengraph('yourlinkid', 'yourworkspaceid')

Deletes OpenGraph metadata for a link.

  • Parameters:
    • link_id: String - ID of the link
    • workspace_id: String (Optional) - Workspace ID
  • Returns: JSON object containing the deleted OpenGraph metadata details