How to get location name from location_id in google adwords using node.js?

404 views
Skip to first unread message

Vasudev

unread,
Apr 9, 2021, 5:51:07 AM4/9/21
to AdWords API and Google Ads API Forum
I found this link https://developers.google.com/adwords/api/docs/appendix/geotargeting which provides all the location names corresponding to location_id in form of .csv file. Is there a way I can do the same with the help of some API using node.js?

Google Ads API Forum Advisor Prod

unread,
Apr 9, 2021, 10:50:11 AM4/9/21
to era...@gmail.com, adwor...@googlegroups.com
Hello,

You can use the query operation from the LocationCriterionService to get a location's name by passing its Id.

Regards,
Anthony

Google Logo
Anthony
Google Ads API Team
 


ref:_00D1U1174p._5004Q2FX9bC:ref

Vasudev

unread,
Apr 9, 2021, 12:42:56 PM4/9/21
to AdWords API and Google Ads API Forum
Hello Anthony,
Thank you for the link. But It says that I have to use  " The SQL-like AWQL query string  " but I don't understand the table in which I will make this query?
Suppose, My location_id=9301955. How exactly will I make this query?
Thanks in Advance,
Harshal. 

Vasudev

unread,
Apr 9, 2021, 12:55:18 PM4/9/21
to AdWords API and Google Ads API Forum
I tried something like: https://adwords.google.com/api/adwords/cm/v201809/LocationCriterionService?"SELECT+id+FROM+LocationCriterionService+WHERE+location_id=9301955"
and
https://adwords.google.com/api/adwords/cm/v201809/LocationCriterionService?"SELECT id FROM LocationCriterionService WHERE location_id=9301955"
from https://developers.google.com/adwords/api/docs/guides/awql
but getting 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Server</faultcode>
            <faultstring>No such operation:  (HTTP GET PATH_INFO: /v201809/LocationCriterionService)</faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

Google Ads API Forum Advisor Prod

unread,
Apr 9, 2021, 2:50:22 PM4/9/21
to era...@gmail.com, adwor...@googlegroups.com
Hello,

Please use the GET operation just as shown here except set a predicate on the Id instead of the LocationName. Let me know if you still face issues.

Cheers,

Vasudev

unread,
Apr 13, 2021, 9:23:10 AM4/13/21
to AdWords API and Google Ads API Forum
I tried the solution given in the above link. I'm using node.js so I tried using the soap kit as suggested in the document.
I tried to run the same example mentioned in the link above because if It works for "locationName". It will work for "Id".

async function getLocationName() {
    let Id = "1000004";
    let LocationName = "Quebec";
    var args = { request: {
      "feilds":["Id", "LocationName", "CanonicalName", "DisplayType",
      "ParentLocations", "Reach"],
      "predicates":["LocationName","IN",LocationName]
      }
    };
soap.createClientAsync(wsdlURL).then((client) => {
      console.log(client);                                                                                 // Returns an object which contains xml script starting as shown below along with other key-values                                                                                                  
      console.log(client.getLocation(args).getLocationName());    //Throws error "client.getLocation is not a function" with or without args      
      return client.MyFunctionAsync(args);
    }).then((result) => {
      console.log(result);
    })
    .catch((e)=> {
      console.log(e)
    });
}

xml: '<?xml version="1.0" encoding="UTF-8"?>\n' +
      '<!-- Generated file, do not edit -->\n' +
      '<!-- Copyright 2021 Google Inc. All Rights Reserved -->\n' +
      '<wsdl:definitions\n' +
      '  targetNamespace="https://adwords.google.com/api/adwords/cm/v201809"\n' +
      '  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"\n' +
      '  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\n' +
      '  <wsdl:types>\n' +

What am I  doing wrong?

Google Ads API Forum Advisor Prod

unread,
Apr 13, 2021, 11:01:13 PM4/13/21
to era...@gmail.com, adwor...@googlegroups.com
Hi Vasudev,

Thank you for your follow up. I work with Anthony and allow me to assist you for now.

Please note that our team is not familiar with node.js and that it is also not supported directly as a client library by the AdWords API. That being said, our team would not be able to help troubleshoot the implementation using node.js.

Moving forward, you can refer here, and also to this guide, for more information on how you can construct your AWQL if you would be using the query method of the LocationCriterionService. I hope this helps.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


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