Getting associated campaign details from membership relationship

So, here’s the flow.

  1. User links their Patreon on our site
  2. We store their access and refresh tokens plus expiry_date
  3. We check if the user is a member of OUR campaign

Step 3 is the tricky part.

I’m testing the API in Insomnia (like Postman), and I’m having trouble navigating the relationships between memberships and campaigns.

Example, I want to do: https://www.patreon.com/api/oauth2/v2/identity?include=memberships&fields[member]=patron_status&fields[member][campaign]=url,pledge_url

Which gives me:

{
	"data": {
		"attributes": {},
		"id": "145142623",
		"relationships": {
			"memberships": {
				"data": [
					{
						"id": "90248b2b-0b4e-434b-83bc-2628ffa07b0b",
						"type": "member"
					}
				]
			}
		},
		"type": "user"
	},
	"included": [
		{
			"attributes": {
				"patron_status": "active_patron"
			},
			"id": "90248b2b-0b4e-434b-83bc-2628ffa07b0b",
			"type": "member"
		}
	],
	"links": {
		"self": "https://www.patreon.com/api/oauth2/v2/user/145142623"
	}
}

Get their patron_status and check if their subscribed campaign’s URL matches ours. I figure there should be a better way to do this – like storing the ID of our Patreon campaign and checking if a user’s memberships are subscribed to our ID.

But, I can’t even pull out associated Campaign data from the API. I tried doing something like fields[member][campaign]=url,pledge_url this in the URL params, hoping it’d return attributes of a user’s subscribed campaigns.

Can someone tell me what I’m missing?

Found the answer after some tinkering:

https://www.patreon.com/api/oauth2/v2/identity?include=memberships.campaign&fields[member]=patron_status

Emphasis on memberships.campaign to query the relationship.

If I had to guess, there’s GraphQL magic afoot.

Anyway, I ended up securely storing my campaign’s ID and checking if the token’s owner is an active patron.

If not, say hello to Google Adsense lol.

I’d still say the docs can be a bit clearer, luckily I know GraphQL to be able to piece it together.

2 Likes

Rather than patron_status, rely on currently_entitled_amount_cents and currently_entitled_tiers after matching the membership to your campaign.