Getting Pledge History (Python or generic request)

Hello,
I’m trying to figure out how to get the pledge history for a member of a campaign. I’ve tried
campaign = api_client.get_campaigns_by_id_members(campaign_id, page_size=50, cursor=cursor,
fields={‘member’: [
‘pledge_history’,
]})
and it returns that pledge_history is not a valid field. The library doesn’t mention pledge_history or pledge events, and I can’t figure out how to get them. I finally figured out how to get the pledge_history of the user using a request, but I need the details from pledge event and don’t know what endpoint to get it from.

suffix = "campaigns/{}/members?include=pledge_history".format(campaign_id)
        response = requests.get(
            "https://www.patreon.com/api/oauth2/v2/{}".format(suffix),
            headers={
                'Authorization': "Bearer {}".format(access_token),
                'User-Agent': "Patreon CGT",
            }
        )
        campaign = response.json()

Please let me know what endpoint to use for this information

Hey NStephenH,

I’m running into the same issue. Were you able to solve for this?

That can be acquired by requesting pledge_history as a relationship over member resource. When requesting the member resource, add pledge_history as a relationship include in the request.

It’s been nearly a year, but here’s how I extract a pledge history. I think it was a formatting issue with my specific request.

Code
 def get_pledge_history(self):
        access_token = self.creator_access_token
        api_client = patreon.API(access_token)
        campaign_id = api_client.get_campaigns(page_size=1).json_data['data'][0]['id']
        total_members = 1
        cursor = None
        members = []
        pledge_data = []
        while len(members) < total_members:
            suffix = "campaigns/{}/members?include=pledge_history&fields[pledge-event]=" \
                     "date%2Ctype%2Cpayment_status%2Ctier_title&fields[member]=email".format(campaign_id)
            if cursor:
                suffix += ("&page[cursor]={}".format(cursor))
            response = requests.get(
                "https://www.patreon.com/api/oauth2/v2/{}".format(suffix),
                headers={
                    'Authorization': "Bearer {}".format(access_token),
                    'User-Agent': "Patreon CGT",
                }
            )

            campaign = response.json()
            members += campaign['data']
            try:
                pledge_data += campaign['included']
            except KeyError:
                print("No members found")
            pagination = campaign['meta']['pagination']
            try:
                total_members = pagination['total']
                print("Downloading members {}/{}".format(len(members), total_members), end="\r", flush=True)
                cursor = pagination['cursors']['next']
            except KeyError as e:
                break

Edit: Formatting

1 Like

pledge_history is nice, and it looks like it’s exactly the same as what we see when we click See all payment history for a particular member.

But am I correct in thinking that in pledge_history, there’s no way to tell whether the payment was for a month or a year? Is there any workaround to be able to differentiate between the length of a subscription?

My goal is to reconstruct the payment history.

UPDATE: There are major differences between what the website shows and the raw pledge history. It seems like the results are somehow non-trivially interpreted.

You should be able to match the pledge_event to the tier, and from the tier you can deduce the cadence (year/month).

Isn’t cadence patron selectable?