Skip to main content

Overview

Once you’ve registered mobile apps in Bit2Connect, you can reuse them across multiple dynamic links by referencing their IDs. This approach simplifies link creation and ensures consistency.

Benefits of Using Saved Apps

Simplified API Calls

Reference apps by ID instead of providing full configuration every time.

Consistency

All links use the same app configuration, ensuring consistent behavior.

Easy Updates

Update app configuration once to affect all associated links.

Reduced Errors

No risk of typos in bundle IDs or package names when reusing saved apps.

Basic Usage

Step 1: List Available Apps

First, retrieve your saved mobile apps to get their IDs:
cURL
curl -X GET "https://api.bit2connect.com/1.0/mobile-apps" \
  -H "X-API-KEY: b2co_your_api_key"
Response
{
  "success": true,
  "data": {
    "apps": [
      {
        "id": "550e8400-e29b-41d4-a716-446655440000",
        "name": "My iOS App",
        "platform": "IOS",
        "bundleId": "com.mycompany.myapp"
      },
      {
        "id": "550e8400-e29b-41d4-a716-446655440001",
        "name": "My Android App",
        "platform": "ANDROID",
        "packageName": "com.mycompany.myapp"
      }
    ]
  }
}
Use the app IDs when creating dynamic links:
cURL
curl -X POST "https://api.bit2connect.com/1.0/links" \
  -H "X-API-KEY: b2co_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "summer-sale",
    "name": "Summer Sale Campaign",
    "payload": {
      "link": "https://yourapp.com/products/summer-sale",
      "iosAppId": "550e8400-e29b-41d4-a716-446655440000",
      "androidAppId": "550e8400-e29b-41d4-a716-446655440001"
    }
  }'
Automatic Configuration: When you provide iosAppId or androidAppId, the platform automatically loads and applies the saved app configuration.

Advanced Patterns

Pattern 1: iOS Only

Create a link that only supports iOS deep linking:
{
  "payload": {
    "link": "https://yourapp.com/content",
    "iosAppId": "550e8400-e29b-41d4-a716-446655440000"
  }
}

Pattern 2: Android Only

Create a link that only supports Android deep linking:
{
  "payload": {
    "link": "https://yourapp.com/content",
    "androidAppId": "550e8400-e29b-41d4-a716-446655440001"
  }
}

Pattern 3: Both Platforms

Support both iOS and Android with a single link:
{
  "payload": {
    "link": "https://yourapp.com/content",
    "iosAppId": "550e8400-e29b-41d4-a716-446655440000",
    "androidAppId": "550e8400-e29b-41d4-a716-446655440001"
  }
}

Pattern 4: Mixed Configuration

Combine saved apps with additional link-specific settings:
{
  "payload": {
    "link": "https://yourapp.com/content",
    "iosAppId": "550e8400-e29b-41d4-a716-446655440000",
    "androidAppId": "550e8400-e29b-41d4-a716-446655440001",
    "social": {
      "title": "Check out this amazing content!",
      "description": "Exclusive offer for our mobile app users",
      "image": "https://yourapp.com/images/promo.jpg"
    },
    "campaign": {
      "utm_source": "summer-campaign",
      "utm_medium": "email",
      "utm_campaign": "2024-summer-sale"
    }
  }
}

Implementation Examples

JavaScript/Node.js

// Store app IDs in your configuration
const config = {
  iosAppId: '550e8400-e29b-41d4-a716-446655440000',
  androidAppId: '550e8400-e29b-41d4-a716-446655440001'
};

// Function to create links with saved apps
async function createDynamicLink(destinationUrl, customCode) {
  const response = await fetch('https://api.bit2connect.com/1.0/links', {
    method: 'POST',
    headers: {
      'X-API-KEY': process.env.BIT2CONNECT_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      code: customCode,
      payload: {
        link: destinationUrl,
        iosAppId: config.iosAppId,
        androidAppId: config.androidAppId
      }
    })
  });
  
  return response.json();
}

// Usage
const link = await createDynamicLink(
  'https://yourapp.com/products/item-123',
  'item-123'
);

console.log('Short URL:', link.data.shortUrl);

Python

import os
import requests

# Store app IDs in your configuration
CONFIG = {
    'ios_app_id': '550e8400-e29b-41d4-a716-446655440000',
    'android_app_id': '550e8400-e29b-41d4-a716-446655440001'
}

def create_dynamic_link(destination_url, custom_code):
    """Create a dynamic link with saved mobile apps"""
    response = requests.post(
        'https://api.bit2connect.com/1.0/links',
        headers={
            'X-API-KEY': os.environ['BIT2CONNECT_API_KEY'],
            'Content-Type': 'application/json'
        },
        json={
            'code': custom_code,
            'payload': {
                'link': destination_url,
                'iosAppId': CONFIG['ios_app_id'],
                'androidAppId': CONFIG['android_app_id']
            }
        }
    )
    
    return response.json()

# Usage
link = create_dynamic_link(
    'https://yourapp.com/products/item-123',
    'item-123'
)

print(f"Short URL: {link['data']['shortUrl']}")

PHP

<?php

// Configuration
$config = [
    'iosAppId' => '550e8400-e29b-41d4-a716-446655440000',
    'androidAppId' => '550e8400-e29b-41d4-a716-446655440001'
];

function createDynamicLink($destinationUrl, $customCode) {
    global $config;
    
    $ch = curl_init('https://api.bit2connect.com/1.0/links');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'X-API-KEY: ' . getenv('BIT2CONNECT_API_KEY'),
        'Content-Type: application/json'
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
        'code' => $customCode,
        'payload' => [
            'link' => $destinationUrl,
            'iosAppId' => $config['iosAppId'],
            'androidAppId' => $config['androidAppId']
        ]
    ]));
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return json_decode($response, true);
}

// Usage
$link = createDynamicLink(
    'https://yourapp.com/products/item-123',
    'item-123'
);

echo "Short URL: " . $link['data']['shortUrl'];

Best Practices

Environment Variables: Store app IDs in environment variables or configuration files, not hardcoded in your application.
Caching: Cache the list of mobile apps locally to avoid repeated API calls when creating multiple links.
Validation: Always validate that your saved app IDs exist before creating links in production.
Fallback Strategy: Consider implementing a fallback to manual configuration if saved app lookup fails.

Migration from Manual to Saved Apps

If you’re currently using manual configuration, here’s how to migrate:

Step 1: Audit Current Configuration

Review your current link creation code to identify common mobile app configurations.

Step 2: Create Mobile Apps

Register your mobile apps once:
# Create iOS app
curl -X POST "https://api.bit2connect.com/1.0/mobile-apps" \
  -H "X-API-KEY: b2co_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "IOS",
    "name": "Production iOS App",
    "bundleId": "com.mycompany.myapp",
    "appStoreFallback": "https://apps.apple.com/app/id123456789"
  }'

# Create Android app
curl -X POST "https://api.bit2connect.com/1.0/mobile-apps" \
  -H "X-API-KEY: b2co_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "ANDROID",
    "name": "Production Android App",
    "packageName": "com.mycompany.myapp",
    "playStoreFallback": "https://play.google.com/store/apps/details?id=com.mycompany.myapp"
  }'

Step 3: Update Your Code

Replace manual configuration with app IDs:
// Before (Manual Configuration)
const link = await createLink({
  payload: {
    link: url,
    ios: {
      bundleId: 'com.mycompany.myapp',
      app_store_fallback: 'https://apps.apple.com/app/id123456789'
    },
    android: {
      package: 'com.mycompany.myapp',
      store_fallback: 'https://play.google.com/store/apps/details?id=com.mycompany.myapp'
    }
  }
});

// After (Using Saved Apps)
const link = await createLink({
  payload: {
    link: url,
    iosAppId: '550e8400-e29b-41d4-a716-446655440000',
    androidAppId: '550e8400-e29b-41d4-a716-446655440001'
  }
});

Troubleshooting

App Not Found Error

If you receive an “App not found” error:
  1. Verify the app ID is correct
  2. Ensure the app belongs to your project
  3. Check that the app hasn’t been deleted

Configuration Not Applied

If mobile app configuration isn’t being applied:
  1. Verify you’re using iosAppId/androidAppId (not ios/android objects)
  2. Check that the saved app has valid configuration
  3. Review the link response to confirm app association

Mixed Configuration Conflicts

When using both iosAppId and manual ios configuration:
  • Saved App Takes Priority: The iosAppId configuration will override manual settings
  • Best Practice: Use either saved apps OR manual configuration, not both

Next Steps