首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pardot Salesforce Python API

Pardot Salesforce Python API
EN

Stack Overflow用户
提问于 2018-07-27 12:52:40
回答 1查看 458关注 0票数 1

我需要使用Python API从Pardot Saleforce对象中获取数据。

有没有人可以分享任何可用的代码片段,以便使用Python从所有Pardot对象(表)中获取数据。

EN

回答 1

Stack Overflow用户

发布于 2019-06-07 21:32:25

我正在开发一个使用pypardot4的Pardot sync解决方案( https://github.com/mneedham91/PyPardot4),它涉及到通过应用编程接口(v4)检索数据。以下是一些针对访问者的API片段,但您可以将其用于几乎任何Pardot API(除了vise...):

代码语言:javascript
复制
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配置数据,如下所示:

代码语言:javascript
复制
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的代码片段:

代码语言:javascript
复制
    "apiList":[
        {
            "apiName": "campaign",
            "clientObject": "campaigns"
        },
        {
            "apiName": "customField",
            "clientObject": "customfields"
        },
        {
            "apiName": "customRedirect",
            "clientObject": "customredirects"
        },
        {
            "apiName": "emailClick",
            "clientObject": "emailclicks",
            "noSortBy": true
        },
...

注意noSortBy字段以及它在代码中的处理方式。

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51550957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档