Giter Club home page Giter Club logo

pypardot's Introduction

PyPardot

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

Using it is simple:

from pypardot.client import PardotAPI


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

# Create a new prospect
p.prospects.create_by_email(email='[email protected]', first_name='Joe', last_name='Schmoe')

# Update a prospect field
p.prospects.update_field_by_email(email='[email protected]', field='company', field_value='Joes Plumbing')

# Send a one-off email
p.emails.send_to_email(prospect_email='[email protected]', email_template_id=123)

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
  • Emails
  • Lists
  • Opportunities
  • Prospects
  • Users
  • Visitor Activities
  • Visitors
  • Visits

Required

Installation

Install PyPardot by running:

pip install pypardot

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='[email protected]', first_name='Joe', last_name='Schmoe')

# Update a prospect field (works with default or custom field)
p.prospects.update_field_by_email(email='[email protected]', field='company', field_value='Joes Plumbing')

# Send a one-off email
p.emails.send_to_email(prospect_email='[email protected]', email_template_id=123)

Extras

PyPardot supports some un-documented API methods:

  • prospects.add_to_list: Adds the prospect to a Pardot list
  • prospects.update_field_by_email: Updates the value for a single default or custom field
  • prospects.read_field_by_email: Returns the value for a single default or custom field
  • More coming soon!

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='[email protected]')
except PardotAPIError, e:
  print(e)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.