CAD BOM sync script fails to transfer custom attributes during automated import

Our automated CAD-to-PLM synchronization script is dropping custom attributes when importing BOM structures from SolidWorks. The script successfully creates the BOM hierarchy and transfers standard attributes like part number and description, but custom fields like material grade, supplier code, and coating specification are missing in SAP PLM after import.

We’re using the PLM API with a Python script that reads the CAD file metadata and posts to the BOM creation endpoint. Standard attributes map correctly, but the custom attributes don’t appear in the final BOM even though they’re present in the API payload.

payload = {
  'partNumber': part_data['number'],
  'customAttributes': custom_attrs  # Not transferring
}
response = requests.post(api_url, json=payload)

This is disrupting our engineering process since teams rely on these attributes for material selection and procurement decisions. We validate the BOM structure but the missing attributes require manual re-entry.

Your payload structure looks incomplete. The PLM API requires custom attributes to be wrapped in a specific schema format with attribute IDs, not just names. You need to map your CAD attribute names to the corresponding SAP PLM attribute IDs. Check the API documentation for the exact schema - it should be something like an array of objects with ‘attributeId’ and ‘value’ pairs rather than a simple key-value dictionary.

Don’t forget about validation rules. Even if you get the attribute IDs right and format the payload correctly, the API might silently drop attributes that fail validation. Material grade might have a restricted value list, supplier code might require a specific format, and coating specification might need to match entries in a reference table. Add validation logic to your script that checks attribute values against PLM rules before sending the API request.

Here’s a comprehensive solution covering all three focus areas:

CAD-to-PLM Attribute Mapping: The core issue is incorrect attribute mapping structure. SAP PLM API requires custom attributes in a specific format with attribute IDs, not names. Update your script to query the metadata endpoint and build a proper mapping:

# Get attribute metadata
meta_response = requests.get(f'{base_url}/api/metadata/attributes')
attr_map = {attr['name']: attr['id'] for attr in meta_response.json()}

# Transform CAD attributes to PLM format
custom_attrs = [
  {'attributeId': attr_map['MaterialGrade'], 'value': part_data['material']},
  {'attributeId': attr_map['SupplierCode'], 'value': part_data['supplier']}
]

API Schema Configuration: Your payload structure needs to match the BOM item schema exactly. The customAttributes field must be an array of attribute objects, not a dictionary:

payload = {
  'partNumber': part_data['number'],
  'description': part_data['desc'],
  'bomItems': [{
    'itemNumber': item['number'],
    'customAttributes': custom_attrs  # Properly formatted array
  }]
}

Also ensure you’re setting the correct content type and API version headers. SAP PLM 2021 requires ‘Content-Type: application/json’ and ‘API-Version: 2.0’ headers for custom attribute processing.

BOM Data Validation: Implement pre-submission validation to catch issues before they cause silent failures:

  1. Attribute existence check: Verify all custom attribute IDs exist in the metadata response before building the payload
  2. Value validation: Query validation rules from the metadata endpoint and check attribute values against allowed ranges, enums, or reference tables
  3. Data type conversion: Convert CAD string values to required PLM types (numeric codes, date formats, boolean flags)
  4. Mandatory field check: Ensure all required attributes are present - some custom attributes might be mandatory for certain part types
  5. Length restrictions: Validate string attribute values against maximum length constraints from the schema

Add comprehensive error handling:

try:
  response = requests.post(api_url, json=payload, headers=headers)
  response.raise_for_status()
  result = response.json()

  # Check for partial success
  if result.get('warnings'):
    log_warnings(result['warnings'])  # Attributes might be dropped

except requests.exceptions.HTTPError as e:
  # API returned error - log full response for debugging
  log_error(f"API Error: {e.response.text}")

Implement a validation report that runs before the actual import. This script should read your CAD file, extract all attributes, validate them against PLM rules, and generate a report of any issues. Only proceed with the import if validation passes completely.

For ongoing monitoring, add logging that captures the full API request and response for each BOM import. This makes it much easier to diagnose issues when attribute mapping rules change or new validation requirements are added in future SAP PLM updates.

Query the attribute metadata endpoint to get the IDs. Most PLM APIs expose a GET endpoint like /api/metadata/attributes that returns all available attributes with their IDs, data types, and validation rules. You should cache this mapping in your script and use it to transform your CAD attributes to the correct API format. Also check if there are any data type conversions needed - sometimes string values from CAD need to be converted to specific formats like enums or numeric codes in PLM.