Aloha Friends,
Apologies for the noobish question, I'm still in my infancy with Python & Programming and I'm trying to find a better way to do a very very manual task.
I would like to get all subscribers from Campaign Monitor using it's API
I've read and re-read the API documentation and arrived at the conclusion that I need to use this snippet of code:
from __future__ import absolute_import
import json
from createsend.createsend import CreateSendBase, BadRequest
from createsend.utils import json_to_py, validate_consent_to_track
class Subscriber(CreateSendBase):
"""Represents a subscriber and associated functionality."""
def __init__(self, auth=None, list_id=None, email_address=None):
self.list_id = list_id
self.email_address = email_address
super(Subscriber, self).__init__(auth)
def get(self, list_id=None, email_address=None, include_tracking_preference=False):
"""Gets a subscriber by list ID and email address."""
params = {
"email": email_address or self.email_address,
"includetrackingpreference": include_tracking_preference,
}
response = self._get("/subscribers/%s.json" %
(list_id or self.list_id), params=params)
return json_to_py(response)
I'm a little lost with the code, I'm unsure if I need to apend the create send class above this with the API key, and would the above just give me a full Json list of my subscribers..?
I'm taking a basic API course on Udemy at the moment so I know how to use postman and run basic api calls using Flask, but I've not seen or used Createsend.
Github for the Code here
Documentation here
For anyone reading this I really appreciate your time, (whether you reply or not)!
Yours Sincerely, Datanovice.
greetings from another novice. Came across your post yesterday as I was trying to add a subscriber to a list using their API. I struggled a bit and could only solve it with the help of a senior dev. so don't beat yourself up. I know it might be a tad late but hope it still helps. if you did solve it meanwhile, do let me know :-)
first of, if you want to get all subscribers to a list, you need to be looking at this part https://www.campaignmonitor.com/api/lists/ The above will probably get you one subscriber at a time. I recommend using something like Postman to do some test GET calls to the API and see which one is getting you the results you need. for example, this is what I get when I made a GET call to all active subscribers to a list:
Otherwise, try this (you should create an instance of the Subscriber class):
I think you can also just do
subscriber.get()to get the details without any arguments.Hope it helps.
Happy coding :-)