Urgent Assistance Needed with Concurrency Issue in Google Ads API Integration

19 views
Skip to first unread message

Saad Ahmad

unread,
Dec 12, 2023, 9:44:30 AM12/12/23
to Google Ads API and AdWords API Forum
Hi Team, 

 am currently integrating a feature that sends email lists to Google Ads via API in a serverless environment. This function operates without control over concurrency, processing batches of SHA256 hashed email addresses. It checks for the existence of a User List with a given name; if absent, it creates a new list and uploads users.

However, I am encountering a concurrency issue. When two instances run concurrently with a new User List name, both attempt to create the User List simultaneously, leading to duplicate lists. This duplication is a critical issue for the project's success.

Below is the relevant TypeScript code snippet:
User List ID Check and Retrieval:
```typescript
async getUserListId(name: string) {
const resp = await this.search({
gaql: `SELECT user_list.id, user_list.resource_name FROM user_list WHERE user_list.name = '${name}'`,
});
if (!resp.results || !resp.results.length) {
return undefined;
}
return resp.results[0].userList.id as string;
}
```
The ID is later converted to a resource name via `customers/${this.customerId}/userLists/${id}`

User List Creation (if ID not found):
```typescript
async createUserList(
name: string,
description: string = 'A user list from Segment CDP',
) {
const resp = await this.userListMutation([
{
create: {
name: name,
description: description,
membershipStatus: "OPEN",
accessReason: "OWNED",
crmBasedUserList: {
uploadKeyType: 'CONTACT_INFO',
dataSourceType: 'FIRST_PARTY',
},
membershipLifeSpan: '10000',
eligibleForSearch: true,
},
},
]);
const body = await resp.json();
return body;
}
```

I am seeking advice on how to handle this concurrency issue effectively. Specifically, how can I ensure that only one User List is created even when multiple instances attempt to create a list with the same name simultaneously?

Please note that the environment I am working on is extremely restrictive an only allows me to access Typescript fetch api and NodeJS crypto library. The only way I can make it work is some REST API feature I am not across. 

Thank you for your assistance.

Best regards,
Saad

Google Ads API Forum Advisor

unread,
Dec 12, 2023, 2:45:14 PM12/12/23
to saad....@servian.com, adwor...@googlegroups.com

Hi Saad,

Thank you for contacting the Google Ads API support team.

After reviewing your concern, I understand that you are seeking assistance related to concurrency issues when sending email lists to Google Ads via API. I would recommend you check the Concurrent Mutates documentation to learn more about concurrent mutations.

If the issue persists, could you please provide us with the complete API logs (request and response with request-id and request header) generated at your end to assist you further?

If you are using a client library and haven't enabled logging yet, I would request that you enable logging for the specific client library that you are using. You can refer to the guides Java, .Net, PHP, Python, Ruby or Perl to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.

You can send the details via Reply privately to the author option or a direct private reply to this email. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02r1LMb:ref"

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages