質問&ディスカッション

rsato
メンバー

Search APIの結果の参照方法

解決

 

お世話になっております。

pythonを使った場合でのAPIでの質問になります

 

 

import hubspot
from pprint import pprint
from hubspot.crm.companies import PublicObjectSearchRequest, ApiException

client = hubspot.Client.create(access_token="my_app_token")

public_object_search_request = PublicObjectSearchRequest(filter_groups=[{"filters":[{"propertyName":"unique_id","operator":"EQ","value":"99999999"}]}])
try:
    api_response = client.crm.companies.search_api.do_search(public_object_search_request=public_object_search_request)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling search_api->do_search: %s\n" % e)

 

 

上記の検索APIで取得したapi_responseを

pprintで参照をすると下記の結果が返ってきます。

 

 

{'paging': None,
 'results': [{'archived': False,
              'archived_at': None,
              'created_at': datetime.datetime(2022, 8, 16, 8, 19, 42, 386000, tzinfo=tzutc()),
              'id': '9389191749',
              'properties': {'createdate': '2022-08-16T08:19:42.386Z',
                             'domain': 'test.com',
                             'hs_lastmodifieddate': '2022-08-16T08:31:19.290Z',
                             'hs_object_id': '9389191749',
                             'name': 'テスト会社'},
              'properties_with_history': None,
              'updated_at': datetime.datetime(2022, 8, 16, 8, 31, 19, 290000, tzinfo=tzutc())}],
 'total': 1}

 

 

この返ってきた値のidやnameやdomainを個々に取得するには

api_responseに対してどのような参照方法を行えば良いでしょうか?
形式としてはJSONではないようです(テキストをコピーして外部のチェックサイトで試してみたところ)
0 いいね!
1件の承認済みベストアンサー
KMurota
解決策
トップ投稿者

Search APIの結果の参照方法

解決

@rsato 

paging, results, total はそれぞれapi_responseのプロパティとしてドット(.)でアクセスできます。


retuned_companies_list = api_response
.results

でlistが返ってきています。


Kan Murota | Founder of Hyper Automation Design Studio
logo

元の投稿で解決策を見る

0 いいね!
1件の返信
KMurota
解決策
トップ投稿者

Search APIの結果の参照方法

解決

@rsato 

paging, results, total はそれぞれapi_responseのプロパティとしてドット(.)でアクセスできます。


retuned_companies_list = api_response
.results

でlistが返ってきています。


Kan Murota | Founder of Hyper Automation Design Studio
logo
0 いいね!