我正在 HubSpot 中開發一個新專案,該專案回傳嵌套的 JSON,如下例所示。我正在嘗試訪問關聯的聯系人 ID,但正在努力正確參考它(我正在尋找的 id 是下面示例中的值“201”)。我已經把這個腳本放在一起,但這個腳本只回傳 JSON 的整個關聯部分,我只想要 id。如何正確參考 ID?
這是腳本的輸出:
{'contacts': {'paging': None, 'results': [{'id': '201', 'type': 'ticket_to_contact'}]}}
這是我放在一起的腳本:
import hubspot
from pprint import pprint
client = hubspot.Client.create(api_key="API_KEY")
try:
api_response = client.crm.tickets.basic_api.get_page(limit=2, associations=["contacts"], archived=False)
for x in range(2):
pprint(api_response.results[x].associations)
except ApiException as e:
print("Exception when calling basic_api->get_page: %s\n" % e)
這是完整的 JSON 的樣子(為了便于閱讀,'contacts' 屬性被縮短了):
{
"results": [
{
"id": "34018123",
"properties": {
"content": "Hi xxxxx,\r\n\r\nCan you clarify on how the blocking of script happens? Is it because of any CSP (or) the script will decide run time for every URL’s getting triggered from browser?\r\n\r\nRegards,\r\nLogan",
"createdate": "2019-07-03T04:20:12.366Z",
"hs_lastmodifieddate": "2020-12-09T01:16:12.974Z",
"hs_object_id": "34018123",
"hs_pipeline": "0",
"hs_pipeline_stage": "4",
"hs_ticket_category": null,
"hs_ticket_priority": null,
"subject": "RE: call followup"
},
"createdAt": "2019-07-03T04:20:12.366Z",
"updatedAt": "2020-12-09T01:16:12.974Z",
"archived": false
},
{
"id": "34018892",
"properties": {
"content": "Hi Guys,\r\n\r\nI see that we were placed back on the staging and then removed again.",
"createdate": "2019-07-03T07:59:10.606Z",
"hs_lastmodifieddate": "2021-12-17T09:04:46.316Z",
"hs_object_id": "34018892",
"hs_pipeline": "0",
"hs_pipeline_stage": "3",
"hs_ticket_category": null,
"hs_ticket_priority": null,
"subject": "Re: Issue due to server"
},
"createdAt": "2019-07-03T07:59:10.606Z",
"updatedAt": "2021-12-17T09:04:46.316Z",
"archived": false,
"associations": {
"contacts": {
"results": [
{
"id": "201",
"type": "ticket_to_contact"
}
]
}
}
}
],
"paging": {
"next": {
"after": "35406270",
"link": "https://api.hubapi.com/crm/v3/objects/tickets?associations=contacts&archived=false&hs_static_app=developer-docs-ui&limit=2&after=35406270&hs_static_app_version=1.3488"
}
}
}
uj5u.com熱心網友回復:
你可以做到api_response.results[x].associations["contacts"]["results"][0]["id"]。
uj5u.com熱心網友回復:
解決這個問題,發布以防其他人在 HubSpot v3 Api 的回應中掙扎。此呼叫的回應架構是:
Response schema type: Object
String results[].id
Object results[].properties
String results[].createdAt
String results[].updatedAt
Boolean results[].archived
String results[].archivedAt
Object results[].associations
Object paging
Object paging.next
String paging.next.after
String paging.next.linkResponse schema type: Object
String results[].id
Object results[].properties
String results[].createdAt
String results[].updatedAt
Boolean results[].archived
String results[].archivedAt
Object results[].associations
Object paging
Object paging.next
String paging.next.after
String paging.next.link
因此,要訪問與工單關聯的聯系人的 ID,您需要使用以下表示法參考它:
api_response.results[1].associations["contacts"].results[0].id
筆記:
- results[x] - 在索引中參考結果
- Associations["contacts"] - 關聯是一個字典物件,你可以通過它的名字訪問聯系人專案
- Associations["contacts"].results 是一個串列 - 由索引 [] 參考
- id - 是一個字串
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/400890.html
上一篇:檢查串列中json物件中的資料
下一篇:谷歌地圖反應中的邊界是什么意思?
