Skip to main content

API wrapper for API v3 & v4 of Pardot marketing automation software.

Project description

PyPardotSF

PyPardotSF is yet another fork of PyPardot/PyPardot4. The main driver for the fork is to address Pardot's authentication change in Spring 2021 to use Salesforce OAuth. (As seen on PyPardot4 Issue #46)

Another new features of PyPardotSF includes:

This is a working prototype and the code is currently being cleaned up and more detailed documentation is underway.

I'm keeping the original MIT License by the previous contributors. Any contributions, including code, documentations, issue reporting are welcome.

Install

pip install PyPardotSF

Salesforce OAuth

Get keys and tokens

Do this once when you do not have consumer key, secret, refresh token:

  1. Open Python's interactive shell and run the following command:
$ python3

>>> from pypardot.client import PardotAPI
>>> p = PardotAPI(version=3)  # verion=4 available
>>> p.setup_salesforce_auth_keys()
  1. Follow the instruction in the command line to get the keys and refresh token.

  2. After you answer all the questions in the console, you should be able to access API commands:

>>> p.prospects.read_by_email(email="daigo@anelen.co")
  1. You can check the values of business unit id, consumer key, secret, and refresh token:
>>> p.business_unit_id
'0Uv*****'
>>> p.sf_consumer_key
'xxxx'
>>> p.sf_consumer_secret
'yyyy'
>>> p.sftoken_refresh
'zzzz'
  1. Please note them for the secondary and/or programmatic access. (See the next section)

Using the API client

from pypardot.client import PardotAPI

version = 3  # 3 or 4
sf_consumer_key = "xxxx"
sf_consumer_secret = "yyyy"
sf_refresh_token = "zzzz"
business_unit_id = "0Uv*****"

p = PardotAPI(
    sf_consumer_key=sf_consumer_key,
    sf_consumer_secret=sf_consumer_secret,
    sf_refresh_token=sf_refresh_token,
    business_unit_id=business_unit_id,
    version=version)
p.prospects.read_by_email(email="daigo@anelen.co")

Bulk Prospect Import

file_name = "data.csv"
columns = [
    {
        "field": "email"
    },
    {
        "field": "pardot_field_a",
        "overwrite": False,
        "nullOverwrite": False
    },
    {
        "field": "pardot_field_b",
        "overwrite": False,
        "nullOverwrite": False
    },
}
results = client.importapi.create(
    file_name=file_name,
    operation="Upsert",
    object="Prospect",
    columns=columns,
    restoreDeleted=config.get("restore_deleted", False),
    )
batch_id = results["id"]
results = client.importapi.update(id=batch_id, state="Ready")

Check the import status at:

API Imports section at Admin->Import->Prospects

Other endpoints

Please see the original PyPardot / PyPardot4 docs.

Contributors wanted

My (Daigo Tanaka) access to Pardot may not be permanent and I curently have access to Ver 3 API. So I would like this repository to be collaborative as possible with the active Python programmers who uses Pardot API. This includes the release process. I don't want to be a gate-keeper or a blocker.

Any bug fixes and enhancements are welcome and I trust your good intentions. Together with the fellow contributors, I will help review the code from good design and coding stand point, but I may not be able to run tests myself for the reason I stated above. So please DO include the following sections in your pull requests:

  1. Reason for code modification. Include GitHub Issue # (create if not exists)
  2. Supporting API version (3, 4 or both)
  3. Manual test description: Method and result.
  4. Risks of change.

Code of Conduct

Please read and acknowledge our Code of Conduct. before using or contributing to this project.

Related projects

  • target-pardot: A singer.io specification that bulk-updates prospect records to Pardot. The program uses PyPardotSF.

About this project

This project is developed by ANELEN and friends. Please check out the ANELEN's open innovation philosophy and other projects

ANELEN

Copyright © 2020~ Anelen Co., LLC

PyPardot4

This is README from the original PyPardot4 by Matt Needham, as of this commit.

PyPardot was originally created by Josh Geller as a wrapper for Version 3 of the Pardot API. I, Matt Needham, have edited PyPardot for compatibility with Version 4 of the Pardot API. Version 4 accommodates multiple prospects with the same email address. If your Pardot org does not have this featured enabled, you must use version 3. To determine if your Pardot org has this feature enabled, check out this guide.

PyPardot is an API wrapper for Pardot, written in Python.

Using it is simple:

from pypardot.client import PardotAPI

p = PardotAPI(
  email='email@email.com',
  password='password',
  user_key='userkey'
)
                
p.authenticate()

# Create a new prospect
p.prospects.create(email='joe@company.com', first_name='Joe', last_name='Schmoe')

# Read data about our prospect
print(p.prospects.read_by_email(email='joe@company.com'))

Features

  • Includes all documented Pardot API operations
  • Handles API key expiration
  • Detailed API error handling

Object Types & Operations

Support for the following object types:

  • Accounts
  • Campaigns
  • Custom Fields
  • Custom Redirects
  • Dynamic Content
  • Emails
  • Email Clicks
  • Email Templates
  • Forms
  • Lifecycle Histories
  • Lifecycle Stages
  • Lists
  • List Memberships
  • Opportunities
  • Prospects
  • Prospect Accounts
  • Tags
  • TagObjects
  • Users
  • Visitor Activities
  • Visitors
  • Visits

Required

Installation

Install PyPardot by running:

pip install pypardot4

Usage

Authentication

To connect to the Pardot API, you'll need the e-mail address, password, and user key associated with your Pardot account. Your user key is available in the Pardot application under My Settings.

The client will authenticate before performing other API calls, but you can manually authenticate as well:

p = PardotAPI(
  email='your_pardot_email',
  password='your_pardot_password',
  user_key='your_pardot_user_key'
)
                
p.authenticate()

Querying Objects

Supported search criteria varies for each object. Check the official Pardot API documentation for supported parameters. Most objects support limit, offset, sort_by, and sort_order parameters. PyPardot returns JSON for all API queries.

Note: Pardot only returns 200 records with each request. Use offset to retrieve matching records beyond this limit.

# Query and iterate through today's prospects
prospects = p.prospects.query(created_after='yesterday')
total = prospects['total_results'] # total number of matching records
for prospect in prospects['prospect']
  print(prospect.get('first_name'))

Editing/Updating/Reading Objects

Supported fields varies for each object. Check the official Pardot API documentation to see the fields associated with each object.

# Create a new prospect
p.prospects.create_by_email(email='joe@company.com', first_name='Joe', last_name='Schmoe')

# Update a prospect field (works with default or custom field)
p.prospects.update_field_by_id(id=23839663, field_name='company', field_value='Joes Plumbing')

# Send a one-off email
p.emails.send_to_email(prospect_email='joe@company.com', email_template_id=123)

Error Handling

Handling expired API keys

Pardot API keys expire after 60 minutes. If PyPardot detects an 'Invalid API key' error during any API call, it will automatically attempt to re-authenticate and obtain a new valid API key. If re-authentication is successful, the API call will be re-issued. If re-authentication fails, a PardotAPIError is thrown.

Invalid API parameters

If an API call is made with missing or invalid parameters, a PardotAPIError is thrown. Error instances contain the error code and message corresponding to error response returned by the API. See Pardot Error Codes & Messages in the official documentation.

Performing API calls is inherently unsafe, so be sure to catch exceptions:

try:
  p.prospects.create_by_email(email='existing.email.address@company.com')
except PardotAPIError, e:
  print(e)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyPardotSF-0.1.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

PyPardotSF-0.1.1-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

Details for the file PyPardotSF-0.1.1.tar.gz.

File metadata

  • Download URL: PyPardotSF-0.1.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for PyPardotSF-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3888404b72a43e9ef4cfa7f28c8f621a12e73a8f9c6e801b23d4261aff27afa6
MD5 78f6dab3fb8f73cb1bf51576b7af368b
BLAKE2b-256 a1ba5e8623888e4a0a3b09d3b9ee0b60e8f31f4c9cf20d0cb4e29fb848d2af55

See more details on using hashes here.

File details

Details for the file PyPardotSF-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: PyPardotSF-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 43.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for PyPardotSF-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6010e0d6d70c892681b6a0672691544a14438aaeeb394b6b6390e38adcdee69
MD5 68d8e78d49dd3d5cb91db8d47533976d
BLAKE2b-256 36db09065c3999e242bfa09d3a0eac5f67dc1e27d270892e13fa016593623be8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page