Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Querying Error#2 and Paginating with Offset #18

@ViolaHempel

Description

@ViolaHempel

Hi Josh,

There is not a lot of documentation/tutorials on Pardot API, so thanks a lot for creating PyPardot!

import requests
import pypardot
import json
import pandas as pd
from pypardot.client import PardotAPI

p = PardotAPI(
                email='my_email',
                password='my_pwd',
                user_key='my_API'
                )

p.authenticate()

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'))`

`Traceback (most recent call last):
  File "C:\Users\viola\Documents\Pardot\Pardot_API.py", line 18, in <module>
    prospects = p.prospects.query(created_after='yesterday')
  File "C:\Python27\lib\site-packages\pypardot\objects\prospects.py", line 15, in query
    result = self._get(path='/do/query', params=kwargs)
  File "C:\Python27\lib\site-packages\pypardot\objects\prospects.py", line 161, in _get
    result = self.client.get(object=object, path=path, params=params)
  File "C:\Python27\lib\site-packages\pypardot\client.py", line 80, in get
    raise err
pypardot.errors.PardotAPIError: Error #2: Invalid action

What could went wrong in prospects.py?

  • How could I fetch all visitoractivities in 2016, for example? You mention to use offset, but how would I make it work in a loop, so that I don't have to specify the offset parameter in the url all the time?

I wrote a while loop and used request/json libraries to get downloads data via Zendesk API call, but Zendesk response format has "next_page" attribute that makes it easy:

import pandas as pd
import requests
import json

downloads_DF = []
url = 'https://my_website.com/reports/api/v1/download-history/?start_date=2016-03-18&end_date=2016-04-30&ordering=timestamp'

while url:
    response = requests.get(url, headers={'Authorization': 'Token hex_number'})
    if response.status_code != 200:
        print('Error with status code {}'.format(response.status_code))
        exit()
    data = response.json()
    downloads_DF.extend(data['results'])
    **url = data['next']**

downloads_data = {'results': downloads_DF}
#Creating Pandas dataframe
recent_downloads_df = pd.DataFrame(downloads_data['results'], columns = ['name', 'timestamp', 'filename', 'platform', 'token', 'version', 'user', 'type', 'description' ])

Is there a way to do something similar with PyPardot?

Thanks!
Viola

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions