Api v2 Find out if user has a pledge to my campaign

Hello,

I am using the patreon/patreon package for PHP.
I am able to execute the login example and retrieve the user with his pledge relations.

Using it on myself, I get this:
included": array:2 [▼
0 => {#280
+“attributes”: {#279
+“currently_entitled_amount_cents”: 0
+“last_charge_date”: “2018-12-03T02:17:31.000+00:00”
+“last_charge_status”: “Paid”
+“lifetime_support_cents”: 4000
+“patron_status”: “former_patron”
+“pledge_relationship_start”: “2018-09-22T13:05:59.093+00:00”
}
+“id”: “ba312e07-16bd-4a5c-9348-1b71a5618682”
+“type”: “member”
}
1 => {#282
+“attributes”: {#281
+“currently_entitled_amount_cents”: 1000
+“last_charge_date”: “2020-01-01T22:05:43.000+00:00”
+“last_charge_status”: “Paid”
+“lifetime_support_cents”: 6000
+“patron_status”: “active_patron”
+“pledge_relationship_start”: “2019-07-22T00:06:24.381+00:00”
}
+“id”: “53d9e81e-debe-43c9-bee6-49a31fa39146”
+“type”: “member”
}

Now this apparently gives me all the pledges of a user, but how do I find out which one is the pledge to my campaign?

I found one way to do it that I’m going to share here, but it seems overly complicated so I’d appreciate advice on a more sane way to do it.

A1. let the user link their patreon account, as in the patreon/patreon github example. Just get the data.attributes.email from the fetch_user() response and link it to your app user

Now to get membership status is a completely different way:

B1. use your creator access token (not the one of the user logged in)
B2. $campaignID = $api_client->fetch_campaigns()[0][‘id’]; (assuming you only have one campaign to worry about)

B3. $membersWithDetails = $api_client->get_data(
“campaigns/$campaignID/members?include=currently_entitled_tiers,address” .
“&fields”. urlencode("[member]") . “=email,full_name,is_follower,last_charge_date,last_charge_status,lifetime_support_cents,currently_entitled_amount_cents,patron_status” .
“&fields”. urlencode("[tier]") . “=amount_cents,created_at,description,discord_role_ids,edited_at,patron_count,published,published_at,requires_shipping,title,url”);`

B4. iterate through $membersWithDetails, store attributes[‘email’], iterate through relationships[‘currently_entitled_tiers’] and store each title.

Now we can get the patreon email of a logged in user (after step A1), as well as their entitled tiers for our campaign, related to that email address (after step B4).

I have same exact question, but less eloquently asked the other day.

From identity API where membership IDs are returned, you can then iterate through all of them because the associated campaign doesn’t appear to be included, issuing members/{$member_id}?include=address,campaign,user,currently_entitled_tiers".

The iterate thru ALL of memberships and frankly call to members with member_id to get tiers seems unnecessary to me. /identity should offer option to get. Maybe it does, but I’ve yet to figure it out. I hope it’s something obvious.