Getting Patron's email address via REST API

Hello!

I am trying to export the patron pledges from our Patreon page into our server via Rest API (so we can enable the perks in our software), but I’ve ran into an issue.

Requesting https://www.patreon.com/api/oauth2/api/campaigns/<campaign_id>/pledges gets me all the pledges and patron ID’s, but it’s missing all the other patron data.

If I follow the “related” link to get the data for that user as well, the returned structure is missing the email field, even if I authorize my request using the Creator’s Access Token.

Is there something I’m missing? I understand that it shouldn’t be public so it can’t be requested by anyone.

But is there any way to fetch the patron’s emails for my campaign?

When you’re authenticated you can access a patron’s email address, however, it’s worth noting that for a reason I’m not sure about, the Patreon API can be accessed in 2 ways which I consider to be “authenticated” and “unauthenticated”. The related links that the API includes are to the “unauthenticated” endpoints, these do not expose private information (e.g: email) unless you’re accessing the unauthenticated endpoint with an active patreon.com session (via your browser).

My recommendation from my experience working with the Patreon platform is that you should ignore the related links: they are not helpful if you’re trying to work with authenticated access.

The Patreon API implements the JSON API specification, which separates out relation attributes from the relations reference. You need to make use of a JSON API client for your chosen platform or you need to parse the JSON yourself to extract the relation data.

For example, a request to campaigns/{campaign}/pledges would return something like this:

{
    "data": [
        {
            "attributes": {
                "declined_since": null
            },
            "id": "1",
            "relationships": {
                "creator": {
                    "data": {
                        "id": "123",
                        "type": "user"
                    },
                    "links": {
                        "related": "https://www.patreon.com/api/user/123"
                    }
                },
                "patron": {
                    "data": {
                        "id": "456",
                        "type": "user"
                    },
                    "links": {
                        "related": "https://www.patreon.com/api/user/456"
                    }
                }
            },
            "type": "pledge"
        }
    ],
    "included": [
        {
            "attributes": {
                "about": "",
                "created": "2015-10-31T17:59:02+00:00",
                "facebook": null,
                "first_name": "John",
                "full_name": "John Doe",
                "gender": 0,
                "image_url": "https://c8.patreon.com/2/400/456",
                "last_name": "Doe",
                "thumb_url": "https://c8.patreon.com/2/400/456",
                "twitch": null,
                "twitter": null,
                "url": "https://www.patreon.com/user?u=456",
                "vanity": null,
                "youtube": null
            },
            "id": "1",
            "relationships": {
                "campaign": {
                    "data": null
                }
            },
            "type": "user"
        }
    ]
}

Therefore to obtain the patron’s email address you need to extract it from the included data. I’d highly recommend using a JSON API client for your platform of choice rather than trying to write your own parser, or ideally if you’re on a platform that has one available then use a Patreon library which hydrates entities for you so you don’t need to do any of this yourself.


Specific to your goal (get a list of email addresses for all of your patrons), if you don’t mind using PHP for this, my Patreon PHP Library can extract a list of all your patrons email addresses in a couple of lines, e.g:

use Squid\Patreon\Patreon;

$patreon = new Patreon('creator_access_token');

$campaign = $patreon->campaigns()->getMyCampaignWithPledges();

echo $campaign->pledges->map(function ($pledge) {
    return $pledge->patron->email;
})->implode(', ');
1 Like

Oh thank you very much! I have completely missed the “included” section in the response.

I am using C# with ASP.NET and unfortunately there doesn’t seem to be an existing library, so I wanted to get some minimal version to extract the data I need with JSON.NET. I’ll try a JSON API library instead.

1 Like