Marketing campaign import fails due to invalid segment ID references

We’re migrating 500+ marketing campaigns from our legacy platform to SAP CX 2205, but the import process fails when campaigns reference customer segments that don’t exist yet in the target system.

The Campaign Import Wizard throws foreign key constraint errors:


Error: Invalid segment reference in campaign CAMP-2024-Q2-001
Segment ID: SEG-GOLD-TIER-2023 not found in target system
Foreign key constraint violation: campaigns.segment_id -> segments.id
Import halted at record 127 of 500

Our campaigns are heavily dependent on segment IDs, product catalog IDs, and email template IDs from the legacy system. These IDs don’t match SAP CX’s auto-generated IDs after import. The partial migration creates inconsistent campaign data, and manually re-mapping 500 campaigns isn’t feasible. How do we handle ID mapping and migration sequencing to maintain referential integrity?

I’ll provide a complete solution addressing foreign key validation, migration sequencing, and ID mapping strategies.

Step 1: Dependency Analysis and Migration Sequencing

Before starting any import, map your entity dependencies:

  1. Level 0 (No dependencies): Customer segments, product catalogs, email templates
  2. Level 1 (Depends on Level 0): Marketing campaigns (references segments + templates)
  3. Level 2 (Depends on Level 1): Campaign executions, A/B test variants

Critical Rule: Always import parent entities before child entities that reference them.

Migration Sequence:


Phase 1: Import customer segments → capture ID mappings
Phase 2: Import email templates → capture ID mappings
Phase 3: Import product catalogs → capture ID mappings
Phase 4: Transform campaign data using ID mappings
Phase 5: Import transformed campaigns
Phase 6: Import campaign execution history (optional)

Step 2: ID Mapping Strategy

Create a mapping table approach to handle ID transformation:

Option A: External Mapping Database

Create a staging database with mapping tables:

CREATE TABLE segment_id_mapping (
  legacy_segment_id VARCHAR(100),
  scx_segment_id VARCHAR(36),
  segment_name VARCHAR(255),
  import_timestamp TIMESTAMP
);

During segment import, populate this table immediately after each successful import.

Option B: CSV Mapping Files

If you don’t have a staging database, use CSV mapping files:

  1. Import segments into SAP CX
  2. Export segments from SAP CX with new IDs
  3. Join export with legacy data on segment name/description
  4. Create mapping CSV: `legacy_id,scx_id,entity_name
  5. Use this mapping to transform campaign references

Step 3: Foreign Key Validation Pre-Import

Before importing campaigns, validate all foreign key references:

import pandas as pd

# Load mapping tables
segment_map = pd.read_csv('segment_id_mapping.csv')
template_map = pd.read_csv('template_id_mapping.csv')

# Load campaign data
campaigns = pd.read_csv('legacy_campaigns.csv')

# Validate segment references
invalid_segments = campaigns[~campaigns['segment_id'].isin(segment_map['legacy_segment_id'])]
if len(invalid_segments) > 0:
    print(f"Warning: {len(invalid_segments)} campaigns reference non-existent segments")
    invalid_segments.to_csv('campaigns_invalid_segments.csv')

This identifies orphaned references before import failure.

Step 4: ID Transformation Process

Transform campaign data to use SAP CX IDs:

# Map segment IDs
segment_lookup = dict(zip(segment_map['legacy_segment_id'], segment_map['scx_segment_id']))
campaigns['segment_id_new'] = campaigns['segment_id'].map(segment_lookup)

# Map template IDs
template_lookup = dict(zip(template_map['legacy_template_id'], template_map['scx_template_id']))
campaigns['template_id_new'] = campaigns['template_id'].map(template_lookup)

# Check for unmapped references
unmapped = campaigns[campaigns['segment_id_new'].isna()]
if len(unmapped) > 0:
    print(f"Error: {len(unmapped)} campaigns have unmapped segment references")
    # Handle unmapped references - either skip or assign default segment

# Export transformed campaigns
campaigns_transformed = campaigns[['campaign_name', 'segment_id_new', 'template_id_new', ...]]
campaigns_transformed.to_csv('campaigns_import_ready.csv', index=False)

Step 5: Handling Complex Multi-Reference Scenarios

If campaigns reference multiple segments (e.g., target segment + exclusion segment):

  1. Create separate columns for each reference type in your mapping
  2. Transform each reference independently
  3. Validate that all references are mapped before import

Step 6: Import Execution with Validation

When importing the transformed campaigns:

  1. Test Import: Import 10-20 campaigns first to validate the mapping
  2. Verify References: Check in SAP CX that campaigns correctly link to segments
  3. Batch Import: Process remaining campaigns in batches of 50-100
  4. Error Handling: Enable “Skip invalid records” to log failures without halting
  5. Post-Import Validation: Query SAP CX to confirm all foreign key relationships are intact

Step 7: Alternative Approach - API-Based Import with Live Lookup

For more dynamic control, use SAP CX OData API:

import requests

# During campaign import, look up segment by name instead of ID
def get_scx_segment_id(segment_name):
    response = requests.get(
        f"{scx_api_url}/Segments?$filter=name eq '{segment_name}'",
        headers={'Authorization': f'Bearer {token}'}
    )
    return response.json()['d']['results'][0]['id']

# Import each campaign with resolved references
for campaign in legacy_campaigns:
    scx_segment_id = get_scx_segment_id(campaign['segment_name'])
    campaign_payload = {
        'name': campaign['name'],
        'segmentId': scx_segment_id,
        'templateId': get_scx_template_id(campaign['template_name'])
    }
    requests.post(f"{scx_api_url}/Campaigns", json=campaign_payload, headers=headers)

This approach eliminates pre-transformation but is slower for large datasets.

Step 8: Maintaining Referential Integrity

After import:

  1. Run integrity checks in SAP CX:

    • Query campaigns with null segment references
    • Verify template associations
    • Check for orphaned campaign executions
  2. Create a reconciliation report:

    • Total campaigns imported vs source count
    • Foreign key validation results
    • List of campaigns requiring manual review

Best Practices

  1. Never import child entities before parents - always respect dependency hierarchy
  2. Maintain audit trail - keep all mapping files for troubleshooting
  3. Use business keys for matching - segment names, template codes (more reliable than legacy IDs)
  4. Test with subset - validate the entire process with 50 campaigns before full migration
  5. Plan for rollback - have a strategy to revert if critical data is corrupted

Handling Your Specific Error

For the error you encountered (segment SEG-GOLD-TIER-2023 not found):

  1. Verify the segment was successfully imported in Phase 1
  2. Check if the segment name matches between legacy and SAP CX
  3. Confirm the mapping table includes this segment
  4. Update the campaign CSV with the new UUID before re-importing
  5. If segment is missing, import it first, then retry campaign import

This systematic approach ensures referential integrity and prevents the foreign key constraint violations you’re experiencing.


This draft is based on general SAP Customer Experience (SAP CX) knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.

This is a classic foreign key dependency problem in data migration. You need to import in the correct sequence: segments first, then email templates, then product catalogs, and finally campaigns. Create a dependency map of your data entities and import in topological order. SAP CX won’t auto-resolve these references - you need to handle the ID mapping externally.

Are you using the standard import wizard or API-based import? The wizard is limited for complex migrations with dependencies. I’d recommend using the OData API to import campaigns programmatically, where you can look up the new segment IDs in SAP CX and update the campaign payload before creating each record. This gives you control over the ID mapping process.

“Tested this on SAP Marketing Cloud 2.0 and importing customer segments before campaigns eliminated all invalid segment ID reference errors during our bulk migration.”

We’re using the Campaign Import Wizard from the admin console. I tried importing segments first, but the new SAP CX segment IDs are completely different from our legacy IDs. For example:

Legacy: SEG-GOLD-TIER-2023

SAP CX: 8a7f3c2e-9d4b-4f1a-a2c3-5e6d7f8g9h0i

How do we map these during campaign import? The campaign CSV still references the old segment IDs. Do we need to manually update all 500+ campaign records with the new UUIDs before import?

Create an ID mapping table during the segment import. When you import segments, export a CSV from SAP CX with the new IDs, then cross-reference with your legacy segment IDs. Use VLOOKUP or a script to update your campaign CSV with the new segment UUIDs before importing campaigns. This is standard practice for migrations with foreign key dependencies. You’ll need similar mapping tables for templates and products.

I’d automate this with an ETL tool rather than manual CSV manipulation. Use SAP Integration Suite or Talend to:

  1. Import segments and capture the mapping (legacy_id → new_id)
  2. Store mappings in a staging database
  3. Transform campaign data by replacing legacy segment IDs with new IDs via lookup
  4. Import transformed campaigns

This approach scales much better than Excel formulas for 500 campaigns with multiple foreign key references each.