---
updatedAt: 2025-11-12T02:15:17.000Z
agentTools:
  projectIndex: https://developers.rebrandly.com/llms.txt
---

# 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:**

```python
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

```python
def get(self, link_id, workspace_id=None)
```

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

```python
def bulk_create(self, workspace_id, links)
```

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

```python
def get_apps(self, workspace_id='')
```

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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

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

**Example:**

```python
# 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