Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

visitoractivity bulk stuff #6

Open
martingaleh opened this issue Mar 7, 2022 · 0 comments
Open

visitoractivity bulk stuff #6

martingaleh opened this issue Mar 7, 2022 · 0 comments

Comments

@martingaleh
Copy link

martingaleh commented Mar 7, 2022

Hello.

I'm not great at github so I don't know if I'm reading this stuff right but somehow the visitoractivites handles bulk export. I coudn't get it to work, so intead I used the PardotAPI's get function to get the visitor activities after setting up the job. The issue with the get function for me is that it only handles json and the bulk export comes in csv, so I had to modify _check_response. Thus I made this, which seems to work. I'm sure there's a more professional version of this.

from pypardot.client import PardotAPI
from pypardot.errors import PardotAPIError

"""
Hello. I had to make this bs because the original pypardot doesn't have the ability to handle csv so I made my own item here.
"""
class KobePardotAPI(PardotAPI):

@staticmethod
def _check_response(response):
"""
Checks the HTTP response to see if it contains JSON. If it does, checks the JSON for error codes and messages.
Raises PardotAPIError if an error was found. If no error was found, returns the JSON. If JSON was not found,
returns the response status code.
"""
if response.headers.get('content-type') == 'application/json':
json = response.json()
error = json.get('err')
if error:
raise PardotAPIError(json_response=json)
return json
elif response.headers.get('content-type') == 'text/csv; charset=utf-8':
return response.text
else: return response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant