Facing problem with customer Id

47 views
Skip to first unread message

Mr. Rahman

unread,
Jan 20, 2025, 3:55:06 AMJan 20
to Google Ads API and AdWords API Forum
exports.googleAdsAccountCallback = asyncHandler(async (req, res) => {
try {
const { code, state } = req.query;
const { userId, organizationId } = JSON.parse(state);

const { tokens } = await oAuth2Client.getToken(code);
oAuth2Client.setCredentials(tokens);

const oauth2 = google.oauth2({ version: 'v2', auth: oAuth2Client });
const userInfoResponse = await oauth2.userinfo.get();
const { id: googleId, email } = userInfoResponse.data;

const googleAdsClient = new GoogleAdsApi({
client_id: '#',
client_secret: '#',
developer_token: '#'
});

let accessibleCustomers;
try {
accessibleCustomers = await googleAdsClient.listAccessibleCustomers({
refresh_token: tokens.refresh_token
});
console.log('Accessible customers:', accessibleCustomers);
} catch (error) {
console.error('Error retrieving accessible customers:', error);
}

let adsManager = await GoogleAdsManager.findOne({
userId: mongoose.Types.ObjectId(userId),
organizationId: organizationId ? mongoose.Types.ObjectId(organizationId) : null,
googleId
});

if (adsManager) {
adsManager.accessToken = tokens.access_token;
adsManager.refreshToken = tokens.refresh_token || adsManager.refreshToken;
adsManager.tokenExpiry = new Date(tokens.expiry_date);
adsManager.isActive = true;
adsManager.lastSyncedAt = new Date();
} else {
const data = {
userId: mongoose.Types.ObjectId(userId),
organizationId: organizationId ? mongoose.Types.ObjectId(organizationId) : null,
googleId,
email,
accessToken: tokens.access_token,
refreshToken: tokens.refresh_token,
tokenExpiry: new Date(tokens.expiry_date)
};
adsManager = new GoogleAdsManager(data);
}

await adsManager.save();

const script = `
<script>
window.opener.postMessage({
status: 'success',
message: 'Google Ads account connected successfully',
data: {
googleId: '${googleId}',
email: '${email}'
}
}, 'http://localhost:3000');
window.close();
</script>
`;

res.send(script);
} catch (error) {
console.error('Error in callback:', error);
const script = `
<script>
window.opener.postMessage({
status: 'error',
message: 'Error connecting Google Ads account'
}, 'http://localhost:3000');
window.close();
</script>
`;
res.send(script);
}
});



Error:

Error retrieving accessible customers: Error: 2 UNKNOWN: Getting metadata from plugin failed with error: invalid_request
    at callErrorFromStatus (D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\call.js:31:19)
    at Object.onReceiveStatus (D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\client.js:193:76)
    at Object.onReceiveStatus (D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:360:141)
    at Object.onReceiveStatus (D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\client-interceptors.js:323:181)
    at D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\resolving-call.js:129:78
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\client.js:161:32)
    at ServiceClientImpl.<anonymous> (D:\NLM\mymanager\server\node_modules\@grpc\grpc-js\build\src\make-client.js:105:19)
    at D:\NLM\mymanager\server\node_modules\google-ads-node\build\src\v17\customer_service_client.js:370:29
    at D:\NLM\mymanager\server\node_modules\google-gax\build\src\normalCalls\timeout.js:44:16
    at repeat (D:\NLM\mymanager\server\node_modules\google-gax\build\src\normalCalls\retries.js:82:25)
    at D:\NLM\mymanager\server\node_modules\google-gax\build\src\normalCalls\retries.js:125:13
    at OngoingCallPromise.call (D:\NLM\mymanager\server\node_modules\google-gax\build\src\call.js:67:27)
    at NormalApiCaller.call (D:\NLM\mymanager\server\node_modules\google-gax\build\src\normalCalls\normalApiCaller.js:34:19)
    at D:\NLM\mymanager\server\node_modules\google-gax\build\src\createApiCall.js:112:30
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 2,
  details: 'Getting metadata from plugin failed with error: invalid_request',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} },
  note: 'Exception occurred in retry method that was not classified as transient'
}

Google Ads API Forum Advisor

unread,
Jan 20, 2025, 8:29:52 AMJan 20
to fredde...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

By reviewing your concern, I understand that you are getting an invalid_request while trying to connect to the Google Ads API. Also, I would recommend you to check this documentation for List Accessible Accounts for more information and could you confirm which version of API you are using retrieving the list of customers?

In order to investigate your issue further, kindly provide us with the complete API logs (request and response with request-id and request header) generated at your end.

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 in Java.NetPHPPythonRuby, 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 direct private reply to this email.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vGxSB:ref" (ADR-00285115)

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5



Mr. Rahman

unread,
Jan 20, 2025, 10:05:24 AMJan 20
to ads...@forumsupport.google, adwor...@googlegroups.com

🙏

Mr. reacted via Gmail

Google Ads API Forum Advisor

unread,
Jan 20, 2025, 12:04:36 PMJan 20
to fredde...@gmail.com, adwor...@googlegroups.com
Hi,

Based on the information provided, I understand that you are using NodeJS library. Since NodeJS is an open source, we don't test, contribute to or maintain these libraries. Any questions you may have should be directed to the owners of the open source projects. Please refer to Community Libraries as per the documentation.

I hope this helps.

Mr. Rahman

unread,
Jan 20, 2025, 12:21:05 PMJan 20
to Google Ads API Forum Advisor, adwor...@googlegroups.com

I'm using a developer token from a account where I have never run ads.

Also that google account is not an MCC account

Is there any chance that I'm getting this error for this ? Cause I have followed exactly the community package.

Also if you can provide the list of curl where I need to authorize the user, create campaign, ad groups, ads etc. I will also need to show the matrix as well.

Mainly I will manage the entire thing after connecting the account in my system.

That will be great help for me if you can provide me the process. 


I'm using node js, express js for backend and react in frontend also mongodb as the database 

Google Ads API Forum Advisor

unread,
Jan 20, 2025, 2:32:49 PMJan 20
to fredde...@gmail.com, adwor...@googlegroups.com

Hi,

Using developer token from an account where you have never run ads and also not an MCC account definitely can’t be a reason for getting an ‘invalid_request’ error.

To authorize a user in Google Ads API, you can invite them to your Google Ads account and assign them an access level. I would recommend you to refer to Manage access to your Google Ads account help center article for more information.

Also, I would recommend you to refer to campaign management documentation to create campaigns and ad groups via Google Ads API.

Reply all
Reply to author
Forward
0 new messages