campaignmonitor / createsend-python

A Python library for the Campaign Monitor API
http://campaignmonitor.github.io/createsend-python
MIT License
57 stars 64 forks source link

How do I get data using createsend? #72

Closed jstrome-lmp closed 3 years ago

jstrome-lmp commented 3 years ago

Hello, thanks for reading!

I am in a little over my head as python is not my home language, however the company I work for wants to take data from Campaign Monitor and put it into our BI platform (which does not have a connector of course).

Here is what I have so far, mostly from the basic usage:

from createsend import *

auth = {'api_key': 'company's api key}
cs = CreateSend(auth)
clients = cs.clients()
campaign_ids = cs.clients()

for cl in clients:
  print("Client: %s" % cl.Name)
  client = Client(auth, cl.ClientID)
  print("- Campaigns:")
  for cm in client.campaigns():
    print("  - %s" % cm.Subject)
    print(" - %s" % cm.CampaignID)

camp1 = Campaign(auth, 'campaign of interest)
print(camp1.summary())

Now when I print the last line, it returns

<class 'createsend.utils.CreateSendModel'>

I have poured through the documentation and am just really unclear on how to get the data out of here. and into a table that I can convert to a csv and upload etc. (The goal is to eventually automate, I've got some experience with R and google cloud build I'm hoping I can transfer over to python).

Any help you can give would be much appreciated, I've been banging my head on a wall with this for awhile now.

Thanks!

jstrome-lmp commented 3 years ago

Alright, for anyone encountering this in the future I hope I can save you some time. This was my solve:

`summary1 = json.loads(campaign1._get(campaign1.uri_for("summary")))`

Now I have an object with class "dict" that I can convert into a .csv and upload the data wherever I want it.

The ._get line was hidden inside the "summary()" function...I'm not sure if this is a bug or working as intended, but it was extremely difficult to figure out from the documentation.

Good luck if you find this and I hope it saves you some time!

mjwills commented 3 years ago

https://github.com/campaignmonitor/createsend-python/blob/ff6500cc3e23b14779c65dd3fed62d9b9aecdd38/test/test_campaign.py#L148 may also be helpful.