![](/img/trans.png)
[英]Hubspot API - Get contact by email is giving HTTP Error 401: Unauthorized
[英]HubSpot API - Search contact by phone
我了解 HubSpot api 提供了一個端點來按姓名或 email 搜索聯系人?
有沒有辦法使用 API 通過電話號碼搜索聯系人?
對於免費試用的在線工具,您可以嘗試Acho 。 我們公司使用它從 HubSpot 獲取數據,並使用其內置的搜索欄來搜索我們需要的特定聯系人。
下面的 Python 代碼適用於我。 這個頁面看起來非常有用。
干杯!
import hubspot
from pprint import pprint
from hubspot.crm.deals import PublicObjectSearchRequest, ApiException
api_key = "your api key"
test_search_url = f'https://api.hubapi.com/crm/v3/objects/contact/search?hapikey='+api_key
headers = {"Content-Type": "application/json"}
payload = {
"filterGroups": [
{
"filters": [
{
"propertyName": "phone",
"operator": "EQ",
"value": "1234567"
}
]
}
],
"properties": [
"firstname", "lastname", "email", "hs_object_id"
]
}
res = requests.post(test_search_url, headers=headers, data=json.dumps(payload))
res.json()
####Output####
# {'total': 1,
# 'results': [{'id': '13701',
# 'properties': {'createdate': '2022-02-10T07:27:18.733Z',
# 'email': 'adi@XXX.com',
# 'firstname': 'XXX K.',
# 'hs_object_id': '13701',
# 'lastmodifieddate': '2022-02-10T07:28:01.033Z',
# 'lastname': None},
# 'createdAt': '2022-02-10T07:27:18.733Z',
# 'updatedAt': '2022-02-10T07:28:01.033Z',
# 'archived': False}]
# }
我有一個 function 完全是用 Python 寫的。
function 返回一個聯系人 ID 數組,但您可以根據需要檢索其他屬性,您必須將它們添加到properties=["id"]
from hubspot import HubSpot
from hubspot.crm.contacts import ApiException
from hubspot.crm.contacts import PublicObjectSearchRequest
def get_contacts_by_phone(phone):
api_client = HubSpot()
api_client = HubSpot(access_token=YOUR_TOKEN)
public_object_search_request = PublicObjectSearchRequest(
filter_groups=[],
sorts=[{"propertyName": "phone", "direction": "DESCENDING"}],
properties=["id"],
query=phone,
limit=100,
)
try:
api_response = api_client.crm.contacts.search_api.do_search(
public_object_search_request=public_object_search_request
)
print(api_response)
contacts_ids = []
for contact in api_response.results:
contacts_ids.append(contact.id)
return contacts_ids
except ApiException as e:
print("Exception when calling search_api->do_search: %s\n" % e)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.