def create_snippet_asset(client, camp_data):
try:
# Define the constants
CUSTOMER_ID = str(camp_data["customer_id"])
AD_GROUP_ID = str(camp_data["ad_group_id"])
# Get the AdGroupExtensionSettingService
ad_group_extension_setting_service = client.get_service("AdGroupExtensionSettingService")
# Create a structure snippet extension
structure_snippet_extension = client.get_type("StructuredSnippetFeedItem")
structure_snippet_extension.header = "Brands"
# string_value = client.get_type("StringValue", version="v14")
structure_snippet_extension.values.extend([
"Nike",
"Adidas",
"Reebok"
])
# Create an ad group extension setting operation
ad_group_extension_setting_operation = client.get_type("AdGroupExtensionSettingOperation")
ad_group_extension_setting = ad_group_extension_setting_operation.create
ad_group_extension_setting.ad_group = ad_group_extension_setting_service.ad_group_path(
CUSTOMER_ID, AD_GROUP_ID
)
ad_group_extension_setting.extension_type = client.enums.ExtensionTypeEnum.STRUCTURED_SNIPPET
ad_group_extension_setting.extension_feed_items.append(structure_snippet_extension)
# Add the ad group extension setting
response = ad_group_extension_setting_service.mutate_ad_group_extension_settings(
customer_id=CUSTOMER_ID, operations=[ad_group_extension_setting_operation]
)
# Print the result
print(f"Created a structure snippet extension with resource name: {response.results[0].resource_name}")
except Exception as e:
print(f'Error occured while creating structure snippet {e}')