Creating new Audience Segment gives 'INVALID_FORMAT" error

72 views
Skip to first unread message

Abdul Ghaffar

unread,
Feb 13, 2023, 5:53:17 AM2/13/23
to Google Ads API and AdWords API Forum
Hi all,

I hope everybody is doing find.

I am trying to create new audience segment via google ads api, but it returns following error:

{
    "message": "com.google.ads.googleads.v10.errors.GoogleAdsException: errors {\n  error_code {\n    string_format_error: INVALID_FORMAT\n  }\n  message: \"The input string value is invalid for the associated field.\"\n  trigger {\n    string_value: \"\"\n  }\n  location {\n    field_path_elements {\n      field_name: \"operations\"\n      index: 0\n    }\n    field_path_elements {\n      field_name: \"create\"\n    }\n    field_path_elements {\n      field_name: \"rule_based_user_list\"\n    }\n    field_path_elements {\n      field_name: \"expression_rule_user_list\"\n    }\n    field_path_elements {\n      field_name: \"rule\"\n    }\n    field_path_elements {\n      field_name: \"rule_item_groups\"\n      index: 0\n    }\n    field_path_elements {\n      field_name: \"rule_items\"\n      index: 0\n    }\n    field_path_elements {\n      field_name: \"name\"\n    }\n  }\n}\nrequest_id: \"r1S1AGdqZiXblIYEcFZMEA\"\n",
    "status": "INTERNAL_SERVER_ERROR",
    "timestamp": "2023-02-13T10:33:51.601+00:00"
}

Following is the code i using to create Audience segment, it's working fine if i provide segment name without space, ex: "dynx_category" but with name "Page URL" it give error:

public class AudienceSegmentService
{
private final Logger LOGGER = LoggerFactory.getLogger(AudienceSegmentService.class);

private final GoogleAdsServiceFactory googleAdsServiceFactory;
private final GoogleAdsContextSettingsUtil context;

@Autowired
public AudienceSegmentService(GoogleAdsServiceFactory googleAdsServiceFactory, GoogleAdsContextSettingsUtil context)
{
this.googleAdsServiceFactory = googleAdsServiceFactory;
this.context = context;
}

public AudienceSegmentDto create(long accountId, AudienceSegmentDto audienceSegmentDto)
{
if (audienceSegmentDto == null)
{
return audienceSegmentDto;
}

LOGGER.info("Audience Segment input: {}", audienceSegmentDto.toString());

UserListRuleItemGroupInfo.Builder ruleItemGroupInfoBuilder = UserListRuleItemGroupInfo.newBuilder();

Map<String, String> rulesParam = audienceSegmentDto.getRulesParam();

rulesParam.forEach((key, value) -> ruleItemGroupInfoBuilder.addRuleItems(createContainsRule(key, value)));

// Specifies that the user list targets visitors of a page based on the provided rule.

ExpressionRuleUserListInfo expressionRuleUserListInfo = ExpressionRuleUserListInfo.newBuilder()
.setRule(UserListRuleInfo.newBuilder().addRuleItemGroups(ruleItemGroupInfoBuilder.build()).setRuleType(
UserListRuleTypeEnum.UserListRuleType.OR_OF_ANDS).build())
.build();

// Defines a representation of a user list that is generated by a rule.
RuleBasedUserListInfo ruleBasedUserListInfo = RuleBasedUserListInfo.newBuilder()
.setPrepopulationStatus(UserListPrepopulationStatusEnum.UserListPrepopulationStatus.REQUESTED)
.setExpressionRuleUserList(expressionRuleUserListInfo)
.build();

// Creates the user list.
UserList userList = UserList.newBuilder()
.setName(audienceSegmentDto.getName())
.setMembershipStatus(UserListMembershipStatusEnum.UserListMembershipStatus.OPEN)
.setMembershipLifeSpan(audienceSegmentDto.getDuration())
.setRuleBasedUserList(ruleBasedUserListInfo)
.build();

// Creates the operation.
UserListOperation operation = UserListOperation.newBuilder().setCreate(userList).build();

try
{

MutateUserListsRequest.Builder builder = MutateUserListsRequest.newBuilder();
builder.addOperations(operation);
builder.setCustomerId(accountId + "");

MutateUserListsResponse response = googleAdsServiceFactory.userListServiceClient()
.mutateUserListsCallable()
.call(builder.build(), context.defaultContext());

String resourceName = response.getResults(0).getResourceName();
audienceSegmentDto.setResourceName(resourceName);

LOGGER.info("Created: " + audienceSegmentDto.getName() + " Resource: " + resourceName);
}
catch (ApiException e)
{
LOGGER.error("EXCEPTION: ", e);
GoogleAdsOperationsUtil.logApiErrors(e, LOGGER);
throw new AudienceSegmentException(e);
}

return audienceSegmentDto;

}

private UserListRuleItemInfo createContainsRule(String name, String value)
{
return UserListRuleItemInfo.newBuilder()
.setName(name)
.setStringRuleItem(UserListStringRuleItemInfo.newBuilder()
.setOperator(UserListStringRuleItemOperatorEnum.UserListStringRuleItemOperator.CONTAINS)
.setValue(value)
.build())
.build();
}
}

I hope someone will be able to help, thanks :) 

Google Ads API Forum Advisor

unread,
Feb 13, 2023, 1:10:59 PM2/13/23
to abdul....@ladenzeile.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to Google Ads API Forum.

It seems like you encountered the INVALID_FORMAT error. In order for us to further investigate why you encountered the said error in your API response, kindly provide us with the complete request and response logs with the request-id generated on your end when you encountered the error, so that our team can take a closer look. I wanted to check on your logs the data you sent to Google Ads API in your request, that made you encounter the error. 

You can provide it via the Reply privately to author option. If this option is not available, then send it instead on this email address googleadsa...@google.com.

For the Java client library, logging can be enabled by following this guide.

Regards,

Google Logo
Abigail
Google Ads API Team
 


ref:_00D1U1174p._5004Q2izUWl:ref
Reply all
Reply to author
Forward
0 new messages