API not returning the Tier I need

Hello Everyone, I have an issue returning the information on the site, I’m not using WordPress just laravel website.

So I’m requesting this
chrome_y3zTjsMBZy

The problem is that I’m not able to know which Tier they have chosen, I would like to add some features based on Tiers so I need to know which one they pledged to.

I get this response from the API

array(3) {
  ["data"]=>
  array(4) {
    ["attributes"]=>
    array(9) {
      ["email"]=>
      string(23) "aryan.shirani@gmail.com"
      ["first_name"]=>
      string(6) "Ashira"
      ["full_name"]=>
      string(6) "Ashira"
      ["image_url"]=>
      string(37) "https://c8.patreon.com/2/200/26699662"
      ["is_email_verified"]=>
      bool(true)
      ["last_name"]=>
      string(0) ""
      ["thumb_url"]=>
      string(37) "https://c8.patreon.com/2/200/26699662"
      ["url"]=>
      string(39) "https://www.patreon.com/user?u=26699662"
      ["vanity"]=>
      NULL
    }
    ["id"]=>
    string(8) "26699662"
    ["relationships"]=>
    array(1) {
      ["memberships"]=>
      array(1) {
        ["data"]=>
        array(6) {
          [0]=>
          array(2) {
            ["id"]=>
            string(36) "acfce325-b5cc-427c-84fd-f29b8b977e8f"
            ["type"]=>
            string(6) "member"
          }
          [1]=>
          array(2) {
            ["id"]=>
            string(36) "497a20b0-c376-40df-964a-5c8610044de4"
            ["type"]=>
            string(6) "member"
          }
          [2]=>
          array(2) {
            ["id"]=>
            string(36) "f30d84a4-fba1-40e0-8d51-89237a137b7b"
            ["type"]=>
            string(6) "member"
          }
          [3]=>
          array(2) {
            ["id"]=>
            string(36) "a6a9cc4c-9cfa-4f72-a043-2e0593eeaadd"
            ["type"]=>
            string(6) "member"
          }
          [4]=>
          array(2) {
            ["id"]=>
            string(36) "b8102c9a-2e47-460a-8783-96c377439ea3"
            ["type"]=>
            string(6) "member"
          }
          [5]=>
          array(2) {
            ["id"]=>
            string(36) "b1f687c5-0978-493d-9067-954cf09072d6"
            ["type"]=>
            string(6) "member"
          }
        }
      }
    }
    ["type"]=>
    string(4) "user"
  }
  ["included"]=>
  array(6) {
    [0]=>
    array(3) {
      ["attributes"]=>
      array(6) {
        ["currently_entitled_amount_cents"]=>
        int(0)
        ["last_charge_date"]=>
        string(29) "2020-08-01T09:59:39.000+00:00"
        ["last_charge_status"]=>
        string(4) "Paid"
        ["lifetime_support_cents"]=>
        int(200)
        ["patron_status"]=>
        string(13) "former_patron"
        ["pledge_relationship_start"]=>
        string(29) "2020-07-17T16:03:47.621+00:00"
      }
      ["id"]=>
      string(36) "acfce325-b5cc-427c-84fd-f29b8b977e8f"
      ["type"]=>
      string(6) "member"
    }
    [1]=>
    array(3) {
      ["attributes"]=>
      array(6) {
        ["currently_entitled_amount_cents"]=>
        int(0)
        ["last_charge_date"]=>
        string(29) "2020-08-01T09:59:39.000+00:00"
        ["last_charge_status"]=>
        string(4) "Paid"
        ["lifetime_support_cents"]=>
        int(200)
        ["patron_status"]=>
        string(13) "former_patron"
        ["pledge_relationship_start"]=>
        string(29) "2020-07-18T06:43:44.169+00:00"
      }
      ["id"]=>
      string(36) "497a20b0-c376-40df-964a-5c8610044de4"
      ["type"]=>
      string(6) "member"
    }
    [2]=>
    array(3) {
      ["attributes"]=>
      array(6) {
        ["currently_entitled_amount_cents"]=>
        int(0)
        ["last_charge_date"]=>
        string(29) "2020-08-01T09:59:39.000+00:00"
        ["last_charge_status"]=>
        string(4) "Paid"
        ["lifetime_support_cents"]=>
        int(200)
        ["patron_status"]=>
        string(13) "former_patron"
        ["pledge_relationship_start"]=>
        string(29) "2020-07-18T06:45:10.074+00:00"
      }
      ["id"]=>
      string(36) "f30d84a4-fba1-40e0-8d51-89237a137b7b"
      ["type"]=>
      string(6) "member"
    }
    [3]=>
    array(3) {
      ["attributes"]=>
      array(6) {
        ["currently_entitled_amount_cents"]=>
        int(0)
        ["last_charge_date"]=>
        string(29) "2020-08-01T09:59:39.000+00:00"
        ["last_charge_status"]=>
        string(4) "Paid"
        ["lifetime_support_cents"]=>
        int(200)
        ["patron_status"]=>
        string(13) "former_patron"
        ["pledge_relationship_start"]=>
        string(29) "2020-07-18T06:47:49.145+00:00"
      }
      ["id"]=>
      string(36) "a6a9cc4c-9cfa-4f72-a043-2e0593eeaadd"
      ["type"]=>
      string(6) "member"
    }
    [4]=>
    array(3) {
      ["attributes"]=>
      array(6) {
        ["currently_entitled_amount_cents"]=>
        int(0)
        ["last_charge_date"]=>
        string(29) "2021-01-30T07:41:06.000+00:00"
        ["last_charge_status"]=>
        string(4) "Paid"
        ["lifetime_support_cents"]=>
        int(121)
        ["patron_status"]=>
        string(13) "former_patron"
        ["pledge_relationship_start"]=>
        string(29) "2021-01-30T07:41:04.391+00:00"
      }
      ["id"]=>
      string(36) "b8102c9a-2e47-460a-8783-96c377439ea3"
      ["type"]=>
      string(6) "member"
    }
    [5]=>
    array(3) {
      ["attributes"]=>
      array(6) {
        ["currently_entitled_amount_cents"]=>
        int(100)
        ["last_charge_date"]=>
        NULL
        ["last_charge_status"]=>
        NULL
        ["lifetime_support_cents"]=>
        int(0)
        ["patron_status"]=>
        string(13) "active_patron"
        ["pledge_relationship_start"]=>
        string(29) "2021-09-02T04:37:50.795+00:00"
      }
      ["id"]=>
      string(36) "b1f687c5-0978-493d-9067-954cf09072d6"
      ["type"]=>
      string(6) "member"
    }
  }
  ["links"]=>
  array(1) {
    ["self"]=>
    string(51) "https://www.patreon.com/api/oauth2/v2/user/26699662"
  }
}
=================================================array(2) {
  ["data"]=>
  array(1) {
    [0]=>
    array(4) {
      ["attributes"]=>
      array(0) {
      }
      ["id"]=>
      string(7) "5191475"
      ["relationships"]=>
      array(1) {
        ["tiers"]=>
        array(1) {
          ["data"]=>
          array(0) {
          }
        }
      }
      ["type"]=>
      string(8) "campaign"
    }
  }
  ["meta"]=>
  array(1) {
    ["pagination"]=>
    array(1) {
      ["total"]=>
      int(1)
    }
  }
}

Anyone can help?

Bottom line up front: I did something similar without having to fuss with tier levels and going too deep into the poorly documented API, so if you’re set on getting the tier data, I don’t know how much I can help. That said, if you’re willing to use a slightly different approach…

If it is the pledge tier for your campaign, all you really need to request access to should be the identity scope for a regular patron, as campaign details for a member of your campaign is always granted–requesting identity.memberships will let you see their other pledges to other people.

If you don’t request identity.memberships then your campaign is always key 0 of the included array, and it should only show you relationships that are related to your campaign.

Past that, because I had to do something similar in my Symfony project, I just built an internal table to match up the amount returned by “currently_entitled_amount_cents” with what I know the tiers to be in cents and worked off that. That value is returned via $current_member['included'][0]['attributes']['currently_entitled_amount_cents']

Alternatively, if you want to do the tiers path, you’re not seeing a tier result in your api return because it look like you’re using your own Patreon account that isn’t a patron of yourself (fun that) to get pledge details. You don’t see a tier because you don’t have one–there’s no relationship for Patreon to display here.

You might want to see if one of your Patrons is willing to help you figure it out–I had to ask one of mine in order to get as far as I did.

Hello!
I had to made 2 more account on patreon to test out, and still not able to return the tiers level, I mhave one account subscribed to tier 1 and one account subscribed to tier 2 and still even if a cal that scope you mentioned I’m not able to see tiers :frowning:

Any other ideas? Should I use the pricing value instead?
Thanks!

Okay, so I’ve looked at the Patreon API docs, the JSONAPI docs, the patreon-php package, and soatok’s fork, and I think I’ve an idea of how you’d do this, but I’ve not tested it yet (I’ll give it a go tomorrow or this weekend, probably).

First you do a call via the API’s fetch_user function, and what you’re actually wanting from this is the $current_member['included'][0]['id'] field. This is the user’s membership ID for a particular campaign. If you only request for your campaign, this is always going to be [0], but if you have others, it could be any of them so you’d have to sort through them to find it. But you’re looking for their membership ID.

Second, on a separate API call, this time using your creator access token and not the patron’s, call fetch_member_details($member_id) of the API bundle with the ID you found above. This should return the tiers a given patron is entitled to.

You may also need to fetch_campaign_details($campaign_id) with the ID of the campaign at least once to get the tier IDs and data to match them up. Looking at what you originally provided, your campaign ID is probably “5191475”.

Again though, I’ve not tested this myself, so I don’t know what the results will actually be.

Check out how the WP plugin does its related calls:

You can request the tiers which the user is entitled to, then map their ids to the tier ids which you can get when you request your campaign details. (Just request them once, save them at your db and refresh occasionally).

The particular request that WP plugin uses which you need to use is:

identity?include=memberships.currently_entitled_tiers,memberships.campaign&fields[user]=email,first_name,full_name,image_url,last_name,thumb_url,url,vanity,is_email_verified&fields[member]=currently_entitled_amount_cents,lifetime_support_cents,campaign_lifetime_support_cents,last_charge_status,patron_status,last_charge_date,pledge_relationship_start

Of course, you must have requested the proper scopes for those while having the user log in too.