[SOLVED] Cannot retrieve fields for tiers

I want to set up content on my site to only be available to certain Tiers. Therefore, when creating the content, I want to list off all available Tiers, allowing the content creator to (on my site) select which Tier will have access to the content. Then, users will be checked for tier when trying to access the content, only being given permission if they are of the correct tier.

To do this, I need to retrieve a list of tiers from the API. However, i am unable to retrieve any data beyond the Tier ID. I’m making a request to: https://www.patreon.com/api/oauth2/v2/campaigns?include=tiers&fields[tier]=description

My response is:

Array ( 
  [0] => Array ( 
    [attributes] => Array ( )
    [id] => 2861149
    [relationships] => Array (
      [tiers] => Array (
        [data] => Array (
          [0] => Array (
            [id] => 3762195
            [type] => tier
          )
        )
      )
    )
    [type] => campaign
  )
) 

I cannot find any way to retrieve fields for Tiers. Is anyone able to assist me with this?

Thank you.

When using api v2 with a v2 client, using the PHP lib at github repo (actually any request should work), with a valid creator access token:

Requesting…

https://www.patreon.com/api/oauth2/v2/campaigns/9999999999?include=benefits,creator,goals,tiers&fields[tier]=title,description

( [tier] is urlencoded above, it doesnt show in the forum. )

…properly brings tier title and description fields:

        [1] => Array
            (
                [attributes] => Array
                    (
                        [description] => Receive a Patron Badge for your CodeBard Site and Forum Profile.  Your contribution will also back the free plugins & software you are using!
                        [title] => Minstrel
                    )

                [id] => 8898989898938398398989
                [type] => tier
            )

        [2] => Array
            (
                [attributes] => Array
                    (
                        [description] => We will list a site URL you give us as a sponsor in our sponsors page at CodeBard.com You will also receive all of the earlier rewards!
                        [title] => Poet
                    )

                [id] => 0909039408989898989899
                [type] => tier
            )

        [3] => Array
            (
                [attributes] => Array
                    (
                        [description] => Receive premium priority support for a free plugin/software of your choosing from CodeBard. You will also receive all of the earlier rewards!
                        [title] => 
                    )

                [id] => 989898989898989898934
                [type] => tier
            )  (.... blah blah blah - after this it shows other tiers .....)

Thank you for taking the time to respond. It confirmed my suspicious.

As I suspected, something is wrong with the API. When I make this call:

campaigns/2861149?include=benefits,creator,goals,tiers&fields' . urlencode('[tier]') . '=title,description'

I get the following:

Array (
  [attributes] => Array ( )
  [id] => 2861149
  [relationships] => Array (
    ...
    [tiers] => Array (
      [data] => Array (
        [0] => Array (
          [id] => 3762195
          [type] => tier
        )
      )
    )
  )
  [type] => campaign
)

So the API is not returning attributes for me. I’ve tried every possible combination.

I’ve emailed Patreon support three times. Zero response, broken API.

Can you reproduce the same conditions i used:

  • Using the PHP lib at github

  • api v2 client calling api v2 endpoint

  • Modifying fetch_campaign_details in API.php to include the tier name and desc:

      public function fetch_campaign_details($campaign_id) {
      	// Fetches details about a campaign - the membership tiers, benefits, creator and goals.  Requires the current user to be creator of the campaign or requires a creator access token
      	return $this->get_data("campaigns/{$campaign_id}?include=benefits,creator,goals,tiers&fields".urlencode("[tier]")."=title,description");}
    

You can use the below example i used (as index.php)

<?php

require_once __DIR__.'/src/API.php';
require_once __DIR__.'/src/OAuth.php';
 
use Patreon\API;
use Patreon\OAuth;

// This example shows you how to create a webhook at Patreon API to notify you when you have any member changes in your campaign

// Create a client first, using your creator's access token
$api_client = new API('CREATORACCESSTOKENHERE');

// If you dont know the campaign id you are targeting already, fetch your campaigns and get the id for the campaign you need. If you already know your campaign id, just skip this part

$campaigns_response = $api_client->fetch_campaigns();

// Get the campaign id
$campaign_id = $campaigns_response['data'][0]['id'];


$response = $api_client->fetch_campaign_details($campaign_id);
echo '<pre>';
print_r($response);
echo '</pre>';

// If all went well, you will receive a response as depicted in the API documentation here
// https://docs.patreon.com/#triggers-v2
// Except it is decoded as an array - or whatever format you set the API client to decode returns in

I just cloned the github repo via ssh to the webroot by using the . to tell github to put the lib in the webroot

git clone git@github.com:Patreon/patreon-php.git .

You can arrange your dir structure however you need.

Thank you for taking the time to reply. This was the response I received:

Array (
  [data] => Array (
    [attributes] => Array ()
    [id] => 2861149
    [relationships] => Array(
      ...
      [tiers] => Array(
        [data] => Array(
          [0] => Array (
            [id] => 3762195
            [type] => tier
          )
        )
      )
    )
    [type] => campaign
  )
  [included] => Array(
    ...
    [1] => Array(
      [attributes] => Array()
        [id] => 3762195
        [type] => tier
      )
    )
  )

(I used your script with the Github library)

Is this a dev/staging installation? Is it possible that you can give me access to this installation to look into it?

Or alternatively i can provide you a dev site ftp so you can set up your environment there.

Do you want my codebase?

Just the codebase (ftp) where the setup is would be enough. Where you set up the php lib from github. also one creator access key that is fresh and valid (v2 key for v2 endpoint, v1 key for v1 endpoint).

As i mentioned, i can give you a disposable ftp to set up your environment there if you wish as well.

My site is not FTP able. It’s on a system that integrates with compose and writes a read-only artifact to the webroot for security purposes.

It’s also a security issue - I can’t put client code onto your server.

Are you a Patreon employee? Or just a helpful developer?

I develop Patreon’s WP plugin as a contractor. Im not an employee evidently, however i have WP plugin’s development and support responsibilities as well as troubleshooting major issues with PHP library.

You can create a totally new dud creator account, and create api client for that and use those in the test installation if you wish. And you can use the disposable domain and ftp installation i am going to give you. Either works.

If you do that, just make sure to create your tiers exactly like you did in your real creator account.

I appreciate your help, but the API is clearly broken. I’ve tested it with my code - and I’m a developer of nearly 20 years, and have integrated with multiple APIs, including pretty much every major one out there, as well as built and maintained APIs, including JSONAPI. I’m confident in my code, and the code you provided me was entirely fine, and using the master branch of the Github library. This isn’t a code problem. It’s a problem with the API.

I really do appreciate your help, but I’ve wasted enough time debugging their broken API. If they can’t even be bothered to reply to support requests, Patreon is a waste of time. What happens if/when something goes wrong?

Everything I can see from how this API is managed shows me that Patreon is not a service I can recommend to clients with good conscience moving forward. The Composer installation provided on the API documentation as being the library to use is outdated by a year. Requests to their support go entirely ignored. The API literally does not work the way it’s supposed to. And they cannot even be bothered to have their people reply on the forums that are built around their product.

It’s an extremely unprofessional, poorly maintained system, and I worry that if something goes wrong, Patreon will not support my clients properly.

I appreciate your help, but the API is clearly broken

Im able to use the api with the exact call you want to make work, without any problems. Along with the same call working in WP plugin in 2000+ installations across the internet which collectively serve multiple millions of visitors per month, as of this very moment.

This signifies one of two things:

  • Either your installation environment has some issue causing this call to not succeed (low chance, but possibility exists)
  • Or your specific Patreon account has an issue which prevents the api from returning the correct data

So basically that call works for practically everyone else but not your account. That is what we need to debug.

That is why i want to replicate your situation in a new installation environment and test if your account specifically has issues.

  • Or your specific Patreon account has an issue which prevents the api from returning the correct data

Most likely. A proper organization would look internally to figure it out. This organization won’t even reply to support requests.

I understand you dont want to cooperate to solve your issue which no one else is experiencing?

I gave you the exact API call I made. I understand you are an external developer, not one of their people who has access to the internals of the system. There is a limit to the support you can provide externally.

A proper support team will take the API call I made, and use their internal systems to make that call and debug the issue backwards from there. This is not something you are able to do without internal access to their servers.

So it’s not that I’m not willing to cooperate, it’s that I’ve already wasted hours on this, and trying to hack together some replication externally, when the proper solution is for the Patreon team to investigate this bug internally, just isn’t worth my time.

Again, I appreciate your help, but this is a problem with Patreon’s internals.

but this is a problem with Patreon’s internals

Making such a statement despite the call works for everyone else would be inaccurate.

If you provide me your valid creator access token via the forum DM to test it on my installation, we can confirm this in 5 minutes.You can refresh the access token later.

Thank you to Codebard for working through the situation with me. It was in fact a bad call in my code, calling json_debug() with the second argument as TRUE, which was stripping out some of the response - including Tier information.

1 Like

Glad to hear the situation was resolved. Good luck with your integration.