This script will extract Pardot Visitor Activity, and load it into a Salesforce Custom Object.
If it is suspected the Consumer Key and Secret have been compromised, or you simply want to rotate/change them, follow these steps:
- In Salesforce Setup, go to App Manager
- Locate the Connected app, likely called
Pardot Script Integration
, use the arrow at the left to View the App. - Click on Manage Consumer Details, causing a Pop up to appear asking for MFA
- Under Staged Consumer Details, click the Generate button.
- Click the Apply button to put these in place.
Next, we will need to tell Heroku that the values changed.
- Log in to Heroku, navigate to the App you need to update
- From the App's Overview page, click Settings
- Click Reveal Config Vars
- Using the pencil icon next to the 2
CONSUMER_
Vars, update the Value with what Salesforce generated. Click Save changes for each one. - (recommended) Test by running the script Ad hoc, steps below.
If for whatever reason you want to run the script manually, follow these steps:
- Log in to Heroku, navigate to the App you want to run
- From the App's Overview page, click Configure Add-ons
- Click Advanced Scheduler
- Near Triggers, look at the right for a More button-link
- Click Execute Trigger, then Confirm
- Close the Browser tab
- Back at the Heroku App page, click the More button at the top right
- Click View logs.
Once the script is done running, you should see Process exited with status 0
with a successful run. If you don't, there's some troubleshooting to be done, and hopefully there is an error message above that gives you a hint.
There are a few things that will need to be set up in Salesforce for this solution to work.
- Create Permission Set
- Create User
- Create Connected App
- Create Heroku App
- Configure Heroku App
- Create a new Permission Set. Give it a name you will remember, recommended:
Pardot Script Access
- Grant the System Permission
Set Audit Fields upon Record Creation
. If you don't see it, you will need to enable it in Setup > User Interface > User Interface - Grant Read & Create access to
Pardot_Activity__c
, and edit access to all fields. - Grant Read object access to
Contact
,Lead
,Campaign
objects. No need to select any fields.
Create a new Salesforce User which will need access to Pardot
- (recommended) First Name:
Pardot Script
- (recommended) Last Name:
Integration
- Alias: allow autofill
- Email: not really needed, though recommend it's an email you can monitor
- Username: whatever you like
- Nickname: whatever you like
- User License:
Salesforce Integration
- Profile:
Salesforce API Only Systems Integrations
(if you've cloned your own profiles from this, pick the right one) - Active:
checked
There is no need to set the password or remember what it is.
Save the new User, then:
- Add the Permission Set License:
Salesforce API Integration
. This allows the User to make API calls, and (if granted by Permissions) access to Salesforce Objects - Add the Permission Set you created above. This grants access to the 4 Salesforce Objects.
In Salesforce Setup, go to App Manager and create a New Connected App.
- (recommended) Connected App Name:
Pardot Script Integration
- API Name: allow autofill
- Contact Email: who should an Admin email next year when looking at this with no clue?
- (recommended) Description:
Allows a Python Script to make API calls to Pardot and Salesforce to automate data tasks.
- Enable OAuth Settings:
checked
- Callback URL:
https://doesntmatter.com
We don't need this, but it is forced as a required field. - Selected OAuth Scopes:
- Manage Pardot services (pardot_api) - This allows the script to get Visitor Activity records from Pardot
- Manage user data via APIs (api) - This allows the script to load
Pardot_Activity__c
with data - Perform requests at any time (refresh_token, offline_access) - This allows the script to run without human intervention
- Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows:
unchecked
- Enable Client Credentials Flow:
checked
Save this new Connected App, then retrieve the Consumer Key and Secret, which will be used later. Annoyingly, this currently pops up a new window requiring MFA before presenting the 2 values.
- Back at the Connected App, click the Manage button at the top.
- Next, click the Edit Policies button, also at the top.
- Client Credentials Flow -> Run As: Select the User you created above
Click Save
Sign up for Heroku. The sign up process is a bit weird where it asks you to choose the kind of plan you want, though it's not actually specified until Apps are created.
Once Signed In, add a Payment Method.
From the Heroku Dashboard https://dashboard.heroku.com/apps, Click the New button
- Select Create new app
- (recommended) App name:
customername-python-script
. If you plan on having more than 1 script run for a customer, you might want to use a more descriptive name. Click the Create app button. After it is created, you will arrive on the Deploy screen, but we'll come back to this later.
Configuration values are specific to this "instance" of the script, running for just this customer.
From the App Overview or Deploy page, click on the Settings tab.
- Click the Reveal Config Vars button
- Add the following:
BUSINESS_UNIT_ID
: this should come from Salesforce Setup > Business Units. Should start withOUv
CONSUMER_KEY
: this came from the Connected App popup screenCONSUMER_SECRET
: this came from the Connected App popup screenDAYS_AGO
: Used for the very first run, decide how far back you might want to populate Salesforce recordsLOGIN_URL
: Should be in the format ofhttps://mydomain.my.salesforce.com
, similar tohttps://coolcompany.my.salesforce.com
From the App Overview page, click on the Deploy tab.
- Deployment method: GitHub
- Search for the repository:
pardot-activity-extract
, click the Connect button - Click the Enable Automatic Deploys, which will cause the app to update if the source code is changed (like for a bug fix).
- Click the Deploy Branch button. This will "build" the app and get it ready to be run.
- The build log will appear and show you its work. Once done, it will disappear and you should see Your app was successfully deployed. Don't bother clicking View, as our app doesn't have anything to look at. (Usually Heroku Apps are web apps)
These steps largely follow a cool blog post: https://medium.com/analytics-vidhya/schedule-a-python-script-on-heroku-a978b2f91ca8
- From the Heroku App Overview or Deploy page, click the Configure Add-ons link
- Find the
Advanced Scheduler
addon, and add it. - Click the Advanced Scheduler link (opens in a new tab)
- Click the Generate API Token button
- Click the Create Trigger button
- (recommended) Name: Daily Process
- Command:
python script.py
- State:
Active
- Type:
Recurring
- Schedule:
Schedule Helper
- Unit of Time:
Day
- Select a time, recommend off-hours. Click Save