> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bit2connect.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Saved Mobile Apps

> Best practices and examples for using saved mobile app configurations in dynamic links

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

<CardGroup cols={2}>
  <Card title="Simplified API Calls" icon="code">
    Reference apps by ID instead of providing full configuration every time.
  </Card>

  <Card title="Consistency" icon="check-circle">
    All links use the same app configuration, ensuring consistent behavior.
  </Card>

  <Card title="Easy Updates" icon="sync">
    Update app configuration once to affect all associated links.
  </Card>

  <Card title="Reduced Errors" icon="shield-check">
    No risk of typos in bundle IDs or package names when reusing saved apps.
  </Card>
</CardGroup>

## Basic Usage

### Step 1: List Available Apps

First, retrieve your saved mobile apps to get their IDs:

```bash cURL theme={null}
curl -X GET "https://api.bit2connect.com/1.0/mobile-apps" \
  -H "X-API-KEY: b2co_your_api_key"
```

```json Response theme={null}
{
  "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"
      }
    ]
  }
}
```

### Step 2: Create Links with Saved Apps

Use the app IDs when creating dynamic links:

```bash cURL theme={null}
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"
    }
  }'
```

<Info>
  **Automatic Configuration**: When you provide `iosAppId` or `androidAppId`, the platform automatically loads and applies the saved app configuration.
</Info>

## Advanced Patterns

### Pattern 1: iOS Only

Create a link that only supports iOS deep linking:

```json theme={null}
{
  "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:

```json theme={null}
{
  "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:

```json theme={null}
{
  "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:

```json theme={null}
{
  "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

```javascript theme={null}
// 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

```python theme={null}
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 theme={null}
<?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

<Tip>
  **Environment Variables**: Store app IDs in environment variables or configuration files, not hardcoded in your application.
</Tip>

<Tip>
  **Caching**: Cache the list of mobile apps locally to avoid repeated API calls when creating multiple links.
</Tip>

<Warning>
  **Validation**: Always validate that your saved app IDs exist before creating links in production.
</Warning>

<Info>
  **Fallback Strategy**: Consider implementing a fallback to manual configuration if saved app lookup fails.
</Info>

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

```bash theme={null}
# 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:

```javascript theme={null}
// 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

* [Mobile Apps Overview](/guides/mobile-apps-overview) - Learn about mobile app concepts
* [Manage Mobile Apps](/guides/manage-mobile-apps) - Complete management guide
* [Create Links API](/api-reference/links/create) - API reference for link creation
