PHP API: Setting parameters for requests

Hi all,

When using the PHP API, I can’t seem to find any way to set the top-level includes for particular endpoints. For example, getting a list of campaign members is simple enough:

$api_client = new API(AdminUserAuth::patreon_creator_access_token);
$campaigns = $api_client->fetch_campaigns();
$firstCampaign = $campaigns['data'][0]['id'];
$campaignInfo = $api_client->fetch_page_of_members_from_campaign($firstCampaign, 100, null);

However, I can’t find anything in the examples or in the api_client object’s methods or fields that allow me to request more information about those members (i.e. user objects) when using this endpoint. Does anyone know how this is done?

You can do this by calling the get_data function directly and by passing that function the end point URL for the API with the parameters you want. This is all the other fetch_[thing] functions are doing is just parsing an input or two and manipulating a string to pass to the get_data function, which given it’s public declaration is callable directly.

For instance, the

$campaignInfo = $api_client->fetch_page_of_members_from_campaign($firstCampaign, 100, null)

call you’re doing, it’s really just calling

$campaignInfo = $api_client->get_data(“campaigns/{$firstCampaign}/members?page%5Bsize%5D=100”)

after it finishes parsing the campaign ID from $firstCampaign, the page size from the 100, and whether or not you want a particular page (cursor, as it is referred to in the code). To add includes to that you should just have to modify it to include the include field, which would look something like below:


Edited for whatever includes you want. To delineate certain fields for those encodes, you expand it further to look something like below:


Fair warning, I’ve not actually tested that string to see if it is perfectly formatted, but it should guide you in the right direction on how to do this.


Thanks a lot for your help! Formatting the string was fine, I’ve gotten it to work now with the parameters I’m after.

1 Like

Yes, fetch functions are only easy to use, packaged calls. You can copy them and write your own fetch_ function for whatever you want.