我需要使用Python API从Pardot Saleforce对象中获取数据。
有没有人可以分享任何可用的代码片段,以便使用Python从所有Pardot对象(表)中获取数据。
发布于 2019-06-07 21:32:25
我正在开发一个使用pypardot4的Pardot sync解决方案( https://github.com/mneedham91/PyPardot4),它涉及到通过应用编程接口(v4)检索数据。以下是一些针对访问者的API片段,但您可以将其用于几乎任何Pardot API(除了vise...):
from pypardot.client import PardotAPI
# ... some code here to read API config ...
email = config['pardot_email']
password = config['pardot_password']
user_key = config['pardot_user_key']
client = PardotAPI(email, password, user_key)
client.authenticate()
# plain query
data = client.visitors.query(sort_by='id')
total = data['total_results']
# beware - max 200 results are returned, need to implement pagination using offset query paramerter
# filtered query
data = client.visitors.query(sort_by='id', id_greater_than=last_id)我还使用了一些自省来迭代我设置的API配置数据,如下所示:
apiList = config['apiList']
# loop through the apis, and call their query method
for api in apiList:
api_name = api['apiName']
api_object_name = api['clientObject']
api_object = getattr(client, api_object_name)
method = 'query'
if api.get('noSortBy', False) == False:
data = getattr(api_object, method)(created_after=latest_sync, sort_by='created_at')
else:
# The API is not consistent, the sort_by criteria is not supported by all resources
data = getattr(api_object, method)(created_after=latest_sync)以及来自apiList配置JSON的代码片段:
"apiList":[
{
"apiName": "campaign",
"clientObject": "campaigns"
},
{
"apiName": "customField",
"clientObject": "customfields"
},
{
"apiName": "customRedirect",
"clientObject": "customredirects"
},
{
"apiName": "emailClick",
"clientObject": "emailclicks",
"noSortBy": true
},
...注意noSortBy字段以及它在代码中的处理方式。
希望这能有所帮助!
https://stackoverflow.com/questions/51550957
复制相似问题