Opteo/google-ads-node

Argument mismatch in makeUnaryRequest

bilalakbar opened this issue · 2 comments

I'm submitting a ...

  • bug report
  • feature request
  • question about the decisions made in the repository
  • question about how to use this project

Summary

Thank you for this library.
I am trying to use the KeywordPlanIdeaService. The sample example call given in the reposiotry works fine for me. So connection and credentials are fine. But using below code, I am getting the Argument mismatch in makeUnaryRequest error that I assume occurs during the request building process. On a side note, is this the right way to set request params ? Initializing each class and calling setters looks too much for a simple request.

const oGoogleAdsClient = new GoogleAdsClient({
  client_id: GOOGLE_CLIENT_ID,
  client_secret: GOOGLE_CLIENT_SECRET,
  developer_token: GOOGLE_ADS_DEVELOPER_KEY,
  login_customer_id: GOOGLE_ADS_ACCOUNT_ID, // my manager account id
  refresh_token: GOOGLE_ADS_ACCOUNT_REFRESH_TOKEN,
  parseResults: true,
});
const customerId = CUSTOMER_ID; // client inside my Manager account

const service = oGoogleAdsClient.getService("KeywordPlanIdeaService");

const request = new GenerateKeywordIdeasRequest();

const language = new StringValue();
language.setValue("EN");
request.setLanguage(language);

const urlValue = new StringValue();
urlValue.setValue("https://example.com/");
const url = new UrlSeed();
url.setUrl(urlValue);
request.setUrlSeed(url);
request.setCustomerId(customerId);

const response: GenerateKeywordIdeaResponse = await service.generateKeywordIdeas(
  request
);

console.log(response);

Other information

[Node] Error: Argument mismatch in makeUnaryRequest
[Node]     at ServiceClient.Client.makeUnaryRequest (/home/xxxx/dev/xxxx/node_modules/grpc/src/client.js:530:11)
[Node]     at ServiceClient.method_func [as generateKeywordIdeas] (/home/xxxx/dev/xxxx/node_modules/grpc/src/client.js:1000:43)
[Node]     at /home/xxxx/dev/adconnector-api/dist/controllers/googleAds/search.js:270:36
[Node]     at Generator.next (<anonymous>)
[Node]     at fulfilled (/home/xxxx/dev/xxxx/dist/controllers/googleAds/search.js:5:58)
[Node]     at processTicksAndRejections (internal/process/task_queues.js:97:5)
xpirt commented

Try wrapping it inside a Promise, like this:

const response: any = await new Promise((resolve, reject) => {
  service.generateKeywordIdeas(request, (err: any, res: any) => {
    resolve(res);
  });
});

Thank you @xpirt .