in marketing-analytics/activation/common-libs/nodejs-common/src/apis/google_ads_api.js [964:1015]
async createCustomerMatchUserList(customerMatchConfig) {
const config = this.getCamelConfig_(customerMatchConfig);
const { customerId, loginCustomerId, listName, uploadKeyType, } = config;
const userList = new UserList({
name: listName,
type: UserListType.CRM_BASED,
crmBasedUserList: { uploadKeyType },
});
const request = new MutateUserListsRequest({
customerId: getCleanCid(customerId),
operations: [{ create: userList }],
validateOnly: this.debugMode, // when true makes no changes
partialFailure: false, // Simplify error handling in creating userlist
});
const client = await this.getUserListServiceClient_();
const options = this.getCallOptions_(loginCustomerId);
try {
/**
* @type {!MutateUserListsResponse}
* @see https://developers.google.com/google-ads/api/reference/rpc/latest/MutateUserListsResponse
*/
const [response] = await client.mutateUserLists(request, options);
const { results } = response; // No `partialFailureError` here.
this.logger.debug(`Created crm userlist from`, customerMatchConfig);
if (!results[0]) {
if (this.debugMode) {
throw new Error('No UserList was created in DEBUG mode.');
} else {
throw new Error('No UserList was created.');
}
}
const { resourceName } = results[0];
const splitted = resourceName.split('/');
return splitted[splitted.length - 1];
} catch (error) {
// Get the details from a wrapped GoogleAdsFailure
if (error.metadata) {
const failures = this.getGoogleAdsFailures_(error.metadata);
if (failures.length > 0) {
if (this.logger.isDebugEnabled())
debugGoogleAdsFailure(failures, request);
const message = failures.map((failure) => {
return failure.errors.map(({ message }) => message).join(' ');
}).join(';');
throw new Error(message);
}
this.logger.warn(
'Got an error with metadata but no GoogleAdsFailure in it', error);
}
throw error;
}
}