简体   繁体   English

无法从 Hubspot 联系人 API 检索联系人地址数据

[英]Unable to retrieve contact address data from Hubspot Contacts API

I'm using Google Apps scripting to access the Hubspot Contacts API and everything works fantastically:我正在使用 Google Apps 脚本来访问 Hubspot 联系人 API,并且一切正常:

 var firstName = (item.properties.hasOwnProperty('firstname')) ? item.properties.firstname.value : "NA";
 var lastName = (item.properties.hasOwnProperty('lastname')) ? item.properties.lastname.value : "NA";
 var fullName = firstName + " " + lastName; 
 var companyName = (item.properties.hasOwnProperty('company')) ? item.properties.company.value : "NA";

...but I can't seem to query anything related to the contact ADDRESS. ...但我似乎无法查询与联系人地址相关的任何内容。

 var streetAddress = (item.properties.hasOwnProperty('address')) ? item.properties.address.value : "NA";
 var cityName = (item.properties.hasOwnProperty('city')) ? item.properties.city.value : "NA";
 var stateName = (item.properties.hasOwnProperty('state')) ? item.properties.state.value : "NA";
 var postalCode = (item.properties.hasOwnProperty('zip')) ? item.properties.zip.value : "NA";

streetAddress , cityName , stateName , postalCode don't seem to return anything from my API queries. streetAddresscityNamestateNamepostalCode似乎没有从我的 API 查询中返回任何内容。 But firstName , lastName , companyName all work fine.但是firstNamelastNamecompanyName都可以正常工作。 I had some trouble retrieving email before and found a solution online.我之前在检索 email 时遇到了一些麻烦,并在网上找到了解决方案。

Any ideas why my code for looking up and assigning Hubspot address information isn't working?任何想法为什么我的查找和分配 Hubspot 地址信息的代码不起作用?

Here is my current URL query (both URLs have the same effect, but the top one is newer and I thought if I was more specific with the API, I could get the right properties):这是我当前的 URL 查询(两个 URL 具有相同的效果,但上面的 URL 较新,我想如果我更具体地使用 API,我可以获得正确的属性):

var url_query = API_URL + "/contacts/v1/lists/all/contacts/all?properties=address&properties=firstname&properties=lastname&properties=company&properties=city&properties=state&properties=zip";
//var url_query = API_URL + "/contacts/v1/lists/all/contacts/all";

 response.contacts.forEach(function(item) {
 var vid = item.vid;
  
 var firstName = (item.properties.hasOwnProperty('firstname')) ? item.properties.firstname.value : "NA";
 var lastName = (item.properties.hasOwnProperty('lastname')) ? item.properties.lastname.value : "NA";
 var fullName = firstName + " " + lastName; 
 var companyName = (item.properties.hasOwnProperty('company')) ? item.properties.company.value : "NA";
 var streetAddress = (item.properties.hasOwnProperty('address')) ? item.properties.address.value : "NA";
 var cityName = (item.properties.hasOwnProperty('city')) ? item.properties.city.value : "NA";
 var stateName = (item.properties.hasOwnProperty('state')) ? item.properties.state.value : "NA";
 var postalCode = (item.properties.hasOwnProperty('zip')) ? item.properties.zip.value : "NA";
 Logger.log(fullName,streetAddress,cityName,stateName,postalCode);
 
 var email = "NA";     
  // Not sure why, but a contact might have multiple identity-profiles, we take the firstone
  item['identity-profiles'][0].identities.forEach(function(identity) {
    if (identity.type == "EMAIL") {
      email = identity.value;
    }
  });

This looks like a simple mistake of not including the desired properties in the URL.这看起来像是一个简单的错误,没有在 URL 中包含所需的属性。 According to the documentation :根据文档

By default, only a few standard properties will be included in the response data.默认情况下,响应数据中只会包含几个标准属性。 If you include the 'property' parameter, then you will instead get the specified property in the response.如果您包含 'property' 参数,那么您将改为在响应中获取指定的属性。 This parameter may be included multiple times to specify multiple properties.可以多次包含此参数以指定多个属性。

It would seem you used an invalid "properties" parameter in your URL by mistake.您似乎错误地在 URL 中使用了无效的“属性”参数。 Here's how I would adjust the code:以下是我将如何调整代码:

var url_query = API_URL + "/contacts/v1/lists/all/contacts/all?property=address&property=firstname&property=lastname&property=company&property=city&property=state&property=zip";

response.contacts.forEach(function(item) {
    var p = item.properties;

    var firstName = (p.hasOwnProperty('firstname')) ? p.firstname.value : "NA";
    var lastName = (p.hasOwnProperty('lastname')) ? p.lastname.value : "NA";
    var fullName = firstName + " " + lastName;
    var companyName = (p.hasOwnProperty('company')) ? p.company.value : "NA";
    var streetAddress = (p.hasOwnProperty('address')) ? p.address.value : "NA";
    var cityName = (p.hasOwnProperty('city')) ? p.city.value : "NA";
    var stateName = (p.hasOwnProperty('state')) ? p.state.value : "NA";
    var postalCode = (p.hasOwnProperty('zip')) ? p.zip.value : "NA";

    var email = "NA";
    // Not sure why, but a contact might have multiple identity-profiles, we take the firstone
    item['identity-profiles'][0].identities.forEach(function(identity) {
        if (identity.type == "EMAIL") {
            email = identity.value;
        }
    });
});

Note that this API will be replaced soon with an updated CRM API , so if this is a new project you may not want to put too much work into code using the old API calls!请注意,此 API 将很快被更新的 CRM API 取代,因此,如果这是一个新项目,您可能不想使用旧的 API 调用在代码中投入太多工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM