### Install Patreon Python Library with Pip Source: https://docs.patreon.com/ Install the Patreon Python library using pip. Ensure dependencies are also installed. ```bash pip install patreon ``` -------------------------------- ### Install Patreon PHP Library with Composer Source: https://docs.patreon.com/ Install the Patreon PHP library using Composer, the standard package manager for PHP. ```bash composer require patreon/patreon ``` -------------------------------- ### Get Campaign Members with Includes and Fields Source: https://docs.patreon.com/ This example demonstrates how to fetch members for a campaign, including their associated addresses and entitled tiers. It specifies which fields to retrieve for members, tiers, and addresses to optimize the response. ```json { "data": [ { "attributes": { "full_name": "Platform Team", "is_follower": false, "last_charge_date": "2018-04-01T21:28:06+00:00", "last_charge_status": "Paid", "lifetime_support_cents": 400, "currently_entitled_amount_cents": 400, "patron_status": "active_patron", }, "id": "03ca69c3-ebea-4b9a-8fac-e4a837873254", "relationships": { "address": { "data": { "id": "12345", "type": "address" } }, "currently_entitled_tiers": { "data": [{ "id": "54321", "type": "tier", }] } }, "type": "member", }, ...other members... ], "included": [ { "attributes": { "addressee": "Platform Team", "city": "San Francisco", "country": "US", "created_at": "2018-06-03T16:23:38+00:00", "line_1": "555 Main St", "line_2": "", "phone_number": null, "postal_code": "94103", "state": "CA" }, "id": "12345", "type": "address" },{ "attributes": { "amount_cents": 100, "created_at": "2018-04-01T04:15:41.403645+00:00", "description": "A tier", "discord_role_ids": ["1234567890"], "edited_at": "2018-04-01T02:55:36.963334+00:00", "patron_count": 32, "published": true, "published_at": "2018-04-01T02:55:36.938342+00:00", "requires_shipping": false, "title": "Patron", "url": "/bePatron?c=1231345&rid=54512321", }, "id": "54321", "type": "tier", }], "meta": { "pagination": { "cursors": { "next": "12345678ab1231cdefg" }, "total": 100 } } } ``` -------------------------------- ### Install Patreon Python Library via requirements.txt Source: https://docs.patreon.com/ Add the Patreon library to your requirements.txt file and install it using pip. This ensures all dependencies are managed. ```bash echo "patreon" >> requirements.txt pip install -r requirements.txt ``` -------------------------------- ### Fetch Campaign and Creator Info in Python Source: https://docs.patreon.com/ A Python example to retrieve campaign and creator information. Remember to substitute 'None' with your creator access token. ```python import patreon access_token = None # Replace with your creator access token api_client = patreon.API(access_token) campaign_response = api_client.fetch_campaign() campaign = campaign_response.data()[0] print('campaign is', campaign) user = campaign.relationship('creator') print('user is', user) ``` -------------------------------- ### Refresh Token Request Example Source: https://docs.patreon.com/ This example shows the format for a POST request to the Patreon API's token endpoint to refresh an OAuth token. ```http POST www.patreon.com/api/oauth2/token grant_type=refresh_token &refresh_token= &client_id= &client_secret= ``` -------------------------------- ### Webhook API Response Example Source: https://docs.patreon.com/ Example of a successful API response when retrieving webhook details. Shows attributes like `last_attempted_at`, `paused`, and `num_consecutive_times_failed`. ```json { "data":{ "attributes":{ "last_attempted_at": null, "paused":false, "num_consecutive_times_failed":0, "secret":"abcdefghiklmnopqrstuvwyz", "triggers":[ "members:create", "members:update", "members:delete" ], "uri":"https://example.com/hooks/patreon" }, "id":"3955", "type":"webhook" } } ``` -------------------------------- ### Webhook API Response Example Source: https://docs.patreon.com/#introduction An example of the API response when retrieving webhook details. It includes attributes like `last_attempted_at`, `paused` status, and configured `triggers`. ```json { "data":{ "attributes":{ "last_attempted_at": null, "paused":false, "num_consecutive_times_failed":0, "secret":"abcdefghiklmnopqrstuvwyz", "triggers":[ "members:create", "members:update", "members:delete" ], "uri":"https://example.com/hooks/patreon" }, "id":"3955", "type":"webhook" } } ``` -------------------------------- ### Java: Fetching User and Pledge Info Source: https://docs.patreon.com/ This Java snippet demonstrates how to use the Patreon API client to get OAuth tokens and retrieve user and pledge data. ```java import com.patreon.OAuth; import com.patreon.API; import org.json.JSONObject; import org.json.JSONArray; ... String clientID = null; // Replace with your data String clientSecret = null; // Replace with your data String creatorID = null; // Replace with your data String redirectURI = null; // Replace with your data String code = null; // get from inbound HTTP request OAuth oauthClient = new OAuth(clientID, clientSecret); JSONObject tokens = oauthClient.getTokens(code, redirectURI); String accessToken = tokens.getString("access_token"); API apiClient = new API(accessToken); JSONObject userResponse = apiClient.fetchUser(); JSONObject user = userResponse.getJSONObject("data"); JSONArray included = userResponse.getJSONArray("included"); JSONObject pledge = null; if (included != null) { for (int i = 0; i < included.length(); i++) { JSONObject object = included.getJSONObject(i); if (object.getString("type").equals("pledge") && object.getJSONObject("relationships").getJSONObject("creator").getJSONObject("data").getString("id").equals(creatorID)) { pledge = object; break; } } } // use the user, pledge, and campaign objects as you desire ``` -------------------------------- ### Create Webhook Payload Source: https://docs.patreon.com/#introduction This is an example payload for creating a new webhook. It specifies the triggers and the URI where notifications will be sent. ```json { "data": { "type": "webhook", "attributes": { "triggers": ["members:create", "members:update", "members:delete"], "uri": "https://www.example.com", }, "relationships": { "campaign": { "data": {"type": "campaign", "id": "12345"}, }, }, }, } ``` -------------------------------- ### Python: Fetching User and Pledge Info Source: https://docs.patreon.com/ This Python snippet shows how to get OAuth tokens and fetch user data, including pledge details, using the Patreon API. ```python import patreon from flask import request ... client_id = None # Replace with your data client_secret = None # Replace with your data creator_id = None # Replace with your data @app.route('/oauth/redirect') def oauth_redirect(): oauth_client = patreon.OAuth(client_id, client_secret) tokens = oauth_client.get_tokens(request.args.get('code'), '/oauth/redirect') access_token = tokens['access_token'] api_client = patreon.API(access_token) user_response = api_client.fetch_user() user = user_response.data() pledges = user.relationship('pledges') pledge = pledges[0] if pledges and len(pledges) > 0 else None ``` -------------------------------- ### Sample Patreon Webhook Payload Source: https://docs.patreon.com/ This is an example of the JSON payload received when a webhook event occurs. It includes details about the pledge, creator, patron, and reward. ```json { "data": { "attributes": { "amount_cents": 250, "created_at": "2015-05-18T23:50:42+00:00", "declined_since": null, "patron_pays_fees": false, "pledge_cap_cents": null }, "id": "1", "relationships": { "address": { "data": null }, "card": { "data": null }, "creator": { "data": { "id": "3024102", "type": "user" }, "links": { "related": "https://www.patreon.com/api/user/3024102" } }, "patron": { "data": { "id": "32187", "type": "user" }, "links": { "related": "https://www.patreon.com/api/user/32187" } }, "reward": { "data": { "id": "599336", "type": "reward" }, "links": { "related": "https://www.patreon.com/api/rewards/599336" } } }, "type": "pledge" }, "included": [ { "** * Creator Object ** *" }, { "** * Patron Object ** *" }, { "** * Reward Object ** *" } ] } ``` -------------------------------- ### Patreon API Pledges HTTPS Request Example Source: https://docs.patreon.com/#introduction This is the format for an HTTPS GET request to retrieve pledges for a specific campaign ID. Ensure you include a valid access token. ```http GET https://www.patreon.com/api/oauth2/api/campaigns//pledges?include=patron.null ``` -------------------------------- ### Fetch Campaign and Creator Info in Java Source: https://docs.patreon.com/ This Java example shows how to fetch campaign and creator details using the Patreon API. You'll need to replace 'null' with your access token and handle JSON parsing manually. ```java import com.patreon.OAuth; import com.patreon.API; import org.json.JSONObject; import org.json.JSONArray; ... String accessToken = null; // Replace with your data API apiClient = new API(accessToken); JSONObject campaignResponse = apiClient.fetchCampaign(); JSONObject campaign = campaignResponse.getJSONObject("data"); JSONArray included = userResponse.getJSONArray("included"); JSONObject user = null; // This will get simplified in future versions of the library. // For now, we must denormalize the JSON:API response by hand. String userID = campaign .getJSONObject("relationships").getJSONObject("creator").getJSONObject("data").getString("id"); if (included != null) { for (int i = 0; i < included.length(); i++) { JSONObject object = included.getJSONObject(i); if (object.getString("type").equals("user") && object.getJSONObject("relationships").getJSONObject("creator").getJSONObject("data").getString("id").equals(userID)) { user = object; break; } } } ``` -------------------------------- ### Fetch Campaign and Creator Info in PHP Source: https://docs.patreon.com/ This PHP snippet demonstrates fetching campaign and creator data. Replace 'null' with your valid access token. ```php fetch_campaign(); $campaign = $campaign_response->get('data')->get('0'); echo "campaign is\n"; print_r($campaign->asArray(true)); $user = $campaign->relationship('creator')->resolve($campaign_response); echo "user is\n"; print_r($user->asArray(true)); ``` -------------------------------- ### Fetch Campaign and Creator Info in Ruby Source: https://docs.patreon.com/ Use this Ruby snippet to fetch campaign and creator details. Ensure you replace 'nil' with your actual access token. ```ruby require 'patreon' access_token = nil # Replace with your data api_client = Patreon::API.new(access_token) campaign_response = api_client.fetch_campaign() campaign = campaign_response.data[0] puts "campaign is", campaign user = campaign.creator puts "user is", user ``` -------------------------------- ### APIv2 Get Live Endpoint Source: https://docs.patreon.com/ Retrieves a specific live event by its ID. ```APIDOC ## GET /api/oauth2/v2/lives/{id} ### Description Retrieves details of a specific live event using its unique identifier. ### Method GET ### Endpoint /api/oauth2/v2/lives/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the live event. ``` -------------------------------- ### Get Campaign Members with Includes and Fields Source: https://docs.patreon.com/#introduction This sample demonstrates how to request members of a campaign, including their associated tiers and addresses. It specifies which fields to return for members, tiers, and addresses, and includes pagination details. ```json { "data": [ { "attributes": { "full_name": "Platform Team", "is_follower": false, "last_charge_date": "2018-04-01T21:28:06+00:00", "last_charge_status": "Paid", "lifetime_support_cents": 400, "currently_entitled_amount_cents": 400, "patron_status": "active_patron" }, "id": "03ca69c3-ebea-4b9a-8fac-e4a837873254", "relationships": { "address": { "data": { "id": "12345", "type": "address" } }, "currently_entitled_tiers": { "data": [{ "id": "54321", "type": "tier" }] } }, "type": "member" }, ...other members... ], "included": [ { "attributes": { "addressee": "Platform Team", "city": "San Francisco", "country": "US", "created_at": "2018-06-03T16:23:38+00:00", "line_1": "555 Main St", "line_2": "", "phone_number": null, "postal_code": "94103", "state": "CA" }, "id": "12345", "type": "address" },{ "attributes": { "amount_cents": 100, "created_at": "2018-04-01T04:15:41.403645+00:00", "description": "A tier", "discord_role_ids": ["1234567890"], "edited_at": "2018-04-01T02:55:36.963334+00:00", "patron_count": 32, "published": true, "published_at": "2018-04-01T02:55:36.938342+00:00", "requires_shipping": false, "title": "Patron", "url": "/bePatron?c=1231345&rid=54512321" }, "id": "54321", "type": "tier" }], "meta": { "pagination": { "cursors": { "next": "12345678ab1231cdefg" }, "total": 100 } } } ``` -------------------------------- ### Sample Response for GET /api/oauth2/v2/members/{member_id} Source: https://docs.patreon.com/ This is a sample JSON response for retrieving a specific member by their ID. It includes details about the member, their address, and user information. The response demonstrates how to use query parameters like `fields` and `include` to customize the returned data. Note that brackets in field parameters must be URL encoded. ```json { "data": { "attributes": { "full_name": "first last", "is_follower": false, "last_charge_date": "2020-10-01T11:18:36.000+00:00" }, "id": "123-456-789", "relationships": { "address": { "data": { "id": "123", "type": "address" }, "links": { "related": "https://www.patreon.com/api/oauth2/v2/address/123" } }, "user": { "data": { "id": "123", "type": "user" }, "links": { "related": "https://www.patreon.com/api/oauth2/v2/user/123" } } }, "type": "member" }, "included": [ { "attributes": { "addressee": "123", "city": "city", "line_1": "line 1", "line_2": "Apt. 101", "postal_code": "123" }, "id": "123", "type": "address" }, { "attributes": {}, "id": "123", "type": "user" } ], "links": { "self": "https://www.patreon.com/api/oauth2/v2/members/123-456-789" } } ``` -------------------------------- ### GET /api/oauth2/v2/posts/{id} Source: https://docs.patreon.com/ Fetches a specific Post using its unique `id`. This endpoint requires the `campaigns.posts` scope. ```APIDOC ## GET /api/oauth2/v2/posts/{id} ### Description Get a particular Post by ID. ### Method GET ### Endpoint /api/oauth2/v2/posts/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the post to retrieve. ``` -------------------------------- ### GET /api/oauth2/v2/campaigns/{campaign_id} Source: https://docs.patreon.com/ Retrieves information about a single Campaign, fetched by campaign ID. Requires the `campaigns` scope. ```APIDOC ## GET /api/oauth2/v2/campaigns/{campaign_id} ### Description Returns information about a single Campaign, fetched by campaign ID. Requires the `campaigns` scope. ### Method GET ### Endpoint /api/oauth2/v2/campaigns/{campaign_id} ### Parameters #### Query Parameters - **fields[campaign]** (string) - Optional - Fields for each include must be explicitly requested i.e. `fields[campaign]=created_at,creation_name` but url encode the brackets i.e. `fields%5Bcampaign%5D=created_at,creation_name` ### Request Example ```json { "example": "https://www.patreon.com/api/oauth2/v2/campaigns/{campaign_id}?fields[campaign]=created_at,creation_name,discord_server_id,image_small_url,image_url,is_charged_immediately,is_monthly,main_video_embed,main_video_url,one_liner,one_liner,patron_count,pay_per_name,pledge_url,published_at,summary,thanks_embed,thanks_msg,thanks_video_url" } ``` ### Response #### Success Response (200) - **data** (object) - Contains the campaign details. - **attributes** (object) - The attributes of the campaign. - **created_at** (string) - The creation timestamp of the campaign. - **creation_name** (string) - The name given to the campaign during creation. - **discord_server_id** (string) - The ID of the associated Discord server. - **image_small_url** (string) - URL for the small campaign image. - **image_url** (string) - URL for the main campaign image. - **is_charged_immediately** (boolean) - Indicates if charges are immediate. - **is_monthly** (boolean) - Indicates if the campaign is monthly. - **main_video_embed** (string) - Embed code for the main video. - **main_video_url** (string) - URL for the main video. - **one_liner** (string) - A short description of the campaign. - **patron_count** (integer) - The number of patrons. - **pay_per_name** (string) - The billing cycle name (e.g., "month"). - **pledge_url** (string) - The URL to pledge to the campaign. - **published_at** (string) - The timestamp when the campaign was published. - **summary** (string) - A summary of the campaign. - **thanks_embed** (string) - Embed code for the thanks message. - **thanks_msg** (string) - The thanks message. - **thanks_video_url** (string) - URL for the thanks video. - **id** (string) - The ID of the campaign. - **type** (string) - The type of the resource, "campaign". #### Response Example ```json { "data": { "attributes": { "created_at": "2018-04-01T15:27:11+00:00", "creation_name": "online communities", "discord_server_id": "1234567890", "image_small_url": "https://example.url", "image_url": "https://example.url", "is_charged_immediately": false, "is_monthly": true, "main_video_embed": null, "main_video_url": null, "one_liner": null, "patron_count": 1000, "pay_per_name": "month", "pledge_url": "/bePatron?c=12345", "published_at": "2018-04-01T18:15:34+00:00", "summary": "The most creator-first API", "thanks_embed": "", "thanks_msg": null, "thanks_video_url": null }, "id": "12345", "type": "campaign" } } ``` ``` -------------------------------- ### Sample Response for GET /api/oauth2/v2/campaigns Source: https://docs.patreon.com/ This JSON object demonstrates the structure of a successful response when fetching campaign data. It includes details about the campaign's attributes, ID, and type, along with pagination metadata. Fields for includes must be explicitly requested and URL encoded. ```json { "data": [ { "attributes": { "created_at": "2018-05-04T23:34:08+00:00", "creation_name": "online communities", "discord_server_id": "1234567890", "google_analytics_id": "1234567890", "has_rss": true, "has_sent_rss_notify": true, "image_small_url": "https://example.url", "image_url": "https://example.url", "is_charged_immediately": false, "is_monthly": false, "is_nsfw": false, "main_video_embed": null, "main_video_url": "https://example.url", "one_liner": null, "patron_count": 2, "pay_per_name": "creation", "pledge_url": "/bePatron?c=1234560", "published_at": "2018-05-09T17:12:01+00:00", "rss_artwork_url": "https://example.url", "rss_feed_title": "My custom feed", "summary": "Putting the internet to work for creators.", "thanks_embed": null, "thanks_msg": null, "thanks_video_url": null }, "id": "1234560", "type": "campaign" } ], "meta": { "pagination": { "total": 1 } } } ``` -------------------------------- ### GET /api/oauth2/v2/posts/{id} Source: https://docs.patreon.com/#introduction Fetches a specific Post using its unique ID. Access to this endpoint is granted via the `campaigns.posts` scope. ```APIDOC ## GET /api/oauth2/v2/posts/{id} ### Description Get a particular Post by ID. ### Method GET ### Endpoint /api/oauth2/v2/posts/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the post to retrieve. ### Scope - campaigns.posts ``` -------------------------------- ### Create Webhook Source: https://docs.patreon.com/ Creates a new webhook subscription on the current user's campaign. Requires the `w:campaigns.webhook` scope. ```APIDOC ## POST /api/oauth2/v2/webhooks ### Description Create a Webhook on the current user’s campaign. Requires the `w:campaigns.webhook` scope. ### Method POST ### Endpoint /api/oauth2/v2/webhooks ``` -------------------------------- ### Patreon OAuth Redirect Request Source: https://docs.patreon.com/ This is the GET request that Patreon redirects to after user authorization. It includes a single-use code and the state parameter. ```http GET https://www.mysite.com/custom-uri ?code= &state= ``` -------------------------------- ### GET /api/oauth2/v2/campaigns Source: https://docs.patreon.com/#introduction Requires the `campaigns` scope. Returns a list of Campaigns owned by the authorized user. Supports top-level `includes` and field requests. ```APIDOC ## GET /api/oauth2/v2/campaigns ### Description Returns a list of Campaigns owned by the authorized user. This endpoint requires the `campaigns` scope. ### Method GET ### Endpoint /api/oauth2/v2/campaigns ### Parameters #### Query Parameters - **includes** (string) - Optional - Top-level includes like `tiers`, `creator`, `benefits`, `goals`. - **fields[campaign]** (string) - Optional - Fields for the campaign, e.g., `created_at`, `creation_name`, `patron_count`. - **fields[tier]** (string) - Optional - Fields for the tier, e.g., `currently_entitled_tiers`. Note: Brackets must be URL encoded, e.g., `fields%5Btier%5D=currently_entitled_tiers`. ### Response #### Success Response (200) - **data** (array) - An array of campaign objects. - **meta** (object) - Metadata about the response, including pagination. ### Response Example ```json { "data": [ { "attributes": { "created_at": "2018-05-04T23:34:08+00:00", "creation_name": "online communities", "discord_server_id": "1234567890", "google_analytics_id": "1234567890", "has_rss": true, "has_sent_rss_notify": true, "image_small_url": "https://example.url", "image_url": "https://example.url", "is_charged_immediately": false, "is_monthly": false, "is_nsfw": false, "main_video_embed": null, "main_video_url": "https://example.url", "one_liner": null, "patron_count": 2, "pay_per_name": "creation", "pledge_url": "/bePatron?c=1234560", "published_at": "2018-05-09T17:12:01+00:00", "rss_artwork_url": "https://example.url", "rss_feed_title": "My custom feed", "summary": "Putting the internet to work for creators.", "thanks_embed": null, "thanks_msg": null, "thanks_video_url": null }, "id": "1234560", "type": "campaign" } ], "meta": { "pagination": { "total": 1 } } } ``` ``` -------------------------------- ### Requesting First Page of Members Source: https://docs.patreon.com/ To paginate API responses, use the `page[count]` query parameter to specify the number of records per request. This example shows how to request the first page of members for a campaign. ```Shell curl --request GET \ --url https://www.patreon.com/api/oauth2/v2/campaigns/$campaign_id/members?page%5Bcount%5D=5 \ --header "Authorization: Bearer $access_token" ``` -------------------------------- ### Requesting Specific Data with Fields and Include Source: https://docs.patreon.com/#introduction Demonstrates how to request specific attributes using the `fields` parameter and how to control included resources and their relationships using the `include` parameter. ```APIDOC ## GET /api/oauth2/api/campaigns//pledges ### Description Retrieves pledges for a given campaign, allowing for the selection of specific attributes and the inclusion or exclusion of related resources. ### Method GET ### Endpoint `/api/oauth2/api/campaigns//pledges` ### Parameters #### Query Parameters - **fields[pledge]** (string) - Optional - Comma-separated list of pledge attributes to retrieve (e.g., `total_historical_amount_cents,is_paused`). - **include** (string) - Optional - Comma-separated list of resources to include (e.g., `reward`). Use `null` to exclude relationships, or `resource.null` to exclude a specific resource's relationships. ### Request Example ``` GET https://www.patreon.com/api/oauth2/api/campaigns//pledges?include=reward&fields[pledge]=total_historical_amount_cents,is_paused ``` ### Response #### Success Response (200) - **data** (object) - The requested pledge data. - **included** (array) - Included resources related to the pledges. - **meta** (object) - Metadata about the response, potentially including pagination information. #### Response Example ```json { "data": [ { "type": "pledge", "attributes": { "total_historical_amount_cents": 1000, "is_paused": false } } ], "included": [ { "type": "reward", "attributes": { "title": "Example Reward" } } ], "meta": {} } ``` ``` -------------------------------- ### Get Webhooks Source: https://docs.patreon.com/ Retrieves a list of webhooks associated with the current user's campaign that were created by the API client. Requires the `w:campaigns.webhook` scope. ```APIDOC ## GET /api/oauth2/v2/webhooks ### Description Get the Webhooks for the current user's Campaign created by the API client. You will only be able to see webhooks created by your client. Requires the `w:campaigns.webhook` scope. Top-level `includes`: `client`, `campaign`. ### Method GET ### Endpoint /api/oauth2/v2/webhooks ### Query Parameters - **fields[webhook]** (string) - Optional - Specifies which fields to include for the webhook object. Example: `last_attempted_at,num_consecutive_times_failed,paused,secret,triggers,uri`. ### Response #### Success Response (200) - **data** (array) - A list of webhook objects. - Each object contains: - **id** (string) - The ID of the webhook. - **type** (string) - The type of the object, should be "webhook". - **attributes** (object) - The attributes of the webhook. - **last_attempted_at** (string) - The timestamp of the last attempted delivery. - **num_consecutive_times_failed** (integer) - The number of consecutive failed delivery attempts. - **paused** (boolean) - Indicates if the webhook is paused. - **secret** (string) - The secret used for signing webhook events. - **triggers** (array of strings) - The list of events that trigger this webhook. - **uri** (string) - The URI where webhook events will be sent. ### Response Example ```json { "data": [ { "attributes": { "last_attempted_at": "2018-04-01T20:09:18+00:00", "num_consecutive_times_failed": 0, "paused": false, "secret": "hereisaverycomplexsecret", "triggers": [ "members:create", "members:delete", "members:update" ], "uri": "https://requestb.in/123456"}, "id": "2793", "type": "webhook" } ] } ``` ``` -------------------------------- ### GET /api/oauth2/v2/campaigns/{campaign_id}/posts Source: https://docs.patreon.com/ Retrieves a list of all Posts associated with a specific Campaign, identified by its `campaign_id`. This operation requires the `campaigns.posts` scope for authorization. ```APIDOC ## GET /api/oauth2/v2/campaigns/{campaign_id}/posts ### Description Get a list of all the Posts on a given Campaign by campaign ID. ### Method GET ### Endpoint /api/oauth2/v2/campaigns/{campaign_id}/posts ### Parameters #### Path Parameters - **campaign_id** (string) - Required - The ID of the campaign to retrieve posts from. ``` -------------------------------- ### Get Webhooks Source: https://docs.patreon.com/#introduction Retrieves a list of Webhooks associated with the current user's Campaign that were created by the API client. This endpoint requires the `w:campaigns.webhook` scope. ```APIDOC ## GET /api/oauth2/v2/webhooks ### Description Get the Webhooks for the current user's Campaign created by the API client. You will only be able to see webhooks created by your client. Requires the `w:campaigns.webhook` scope. Top-level `includes`: `client`, `campaign`. ### Method GET ### Endpoint /api/oauth2/v2/webhooks ### Parameters #### Query Parameters - **fields[webhook]** (string) - Optional - Specifies which fields of the webhook object to include in the response. Example: `last_attempted_at,num_consecutive_times_failed,paused,secret,triggers,uri`. ### Response #### Success Response (200) - **data** (array) - A list of webhook objects. - **id** (string) - The ID of the webhook. - **type** (string) - The type of the object, always "webhook". - **attributes** (object) - The attributes of the webhook. - **last_attempted_at** (string) - The timestamp of the last webhook attempt. - **num_consecutive_times_failed** (integer) - The number of consecutive failed attempts. - **paused** (boolean) - Indicates if the webhook is paused. - **secret** (string) - The secret used for webhook verification. - **triggers** (array) - A list of events that trigger the webhook. - **uri** (string) - The URI where the webhook events will be sent. ### Response Example ```json { "data": [ { "attributes": { "last_attempted_at": "2018-04-01T20:09:18+00:00", "num_consecutive_times_failed": 0, "paused": false, "secret": "hereisaverycomplexsecret", "triggers": [ "members:create", "members:delete", "members:update" ], "uri": "https://requestb.in/123456"}, "id": "2793", "type": "webhook" } ] } ``` ``` -------------------------------- ### Ruby: Fetching User and Pledge Info Source: https://docs.patreon.com/ Use this Ruby snippet to initiate the OAuth flow and retrieve a patron's user data and their pledge information. ```ruby require 'patreon' class OAuthController < ApplicationController def redirect oauth_client = Patreon::OAuth.new(client_id, client_secret) tokens = oauth_client.get_tokens(params[:code], redirect_uri) access_token = tokens['access_token'] api_client = Patreon::API.new(access_token) user_response = api_client.fetch_user() @user = user_response.data @pledge = @user.pledges ? @user.pledges[0] : nil end end ``` -------------------------------- ### GET /api/oauth2/v2/lives/{id} Source: https://docs.patreon.com/#introduction Retrieves a specific Live livestream by its ID. This endpoint requires the `campaigns.lives` scope and returns the current state and streaming information for the livestream. ```APIDOC ## GET /api/oauth2/v2/lives/{id} ### Description Get a particular Live livestream by ID. Returns the current state and streaming information for the livestream. ### Method GET ### Endpoint /api/oauth2/v2/lives/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the livestream to retrieve. ### Response #### Success Response (200) - **data** (object) - Contains livestream details. - **id** (string) - The ID of the livestream. - **type** (string) - The type of resource, expected to be "live". - **attributes** (object) - Contains livestream attributes. - **title** (string) - The title of the livestream. - **description** (string) - The description of the livestream. - **state** (string) - The current state of the livestream (e.g., `pre_live`). - **rtmp_url** (string) - The RTMP URL for streaming. - **stream_key** (string) - The stream key for authentication. ### Response Example ```json { "data": { "id": "1235", "type": "live", "attributes": { "title": "", "description": "", "state": "pre_live", "rtmp_url": "", "stream_key": "" } } } ``` ### Scope - campaigns.lives ``` -------------------------------- ### Get Webhooks Sample Response Source: https://docs.patreon.com/ This snippet displays a sample JSON response for retrieving webhooks associated with a user's campaign. It includes details like last attempted time, failure count, paused status, secret, triggers, and URI. Requires the `w:campaigns.webhook` scope. ```json // Sample response https://www.patreon.com/api/oauth2/v2/webhooks/?fields[webhook]=last_attempted_at,num_consecutive_times_failed,paused,secret,triggers,uri { "data": [ { "attributes": { "last_attempted_at": "2018-04-01T20:09:18+00:00", "num_consecutive_times_failed": 0, "paused": false, "secret": "hereisaverycomplexsecret", "triggers": [ "members:create", "members:delete", "members:update" ], "uri": "https://requestb.in/123456"}, "id": "2793", "type": "webhook", }, ], } ``` -------------------------------- ### Pagination for API Endpoints Source: https://docs.patreon.com/#introduction Explains how to paginate through results using `page[count]` to set the page size and `page[cursor]` to retrieve subsequent pages of data. ```APIDOC ## GET /api/oauth2/v2/campaigns/$campaign_id/members ### Description Retrieves a paginated list of members for a given campaign. ### Method GET ### Endpoint `/api/oauth2/v2/campaigns/$campaign_id/members` ### Parameters #### Query Parameters - **page[count]** (integer) - Optional - The maximum number of records to return per page. Maximum is typically 1000, but may be lower. - **page[cursor]** (string) - Optional - A cursor value obtained from a previous response's `meta.pagination.cursors.next` to fetch the next page of results. ### Request Example (First Page) ``` curl --request GET \ --url https://www.patreon.com/api/oauth2/v2/campaigns/$campaign_id/members?page%5Bcount%5D=5 \ --header "Authorization: Bearer $access_token" ``` ### Response #### Success Response (200) - **data** (object) - The requested member data. - **meta** (object) - Metadata containing pagination details. - **meta.pagination.total** (integer) - The total number of records available. - **meta.pagination.cursors.next** (string|null) - A cursor for the next page of results. `null` if this is the last page. #### Response Example (First Page) ```json { "data": {}, "meta": { "pagination": { "total": 10, "cursors": { "next": "03:eyJ2IjoxLCJjIjoiNmY2YWMxMGUtYmU2NS00MTc5LWEyODktMzkwZGMxMTFhMTQ1IiwidCI6IiJ9:1V2dmthW5w5REEsle2scJmOm" } } } } ``` ### Request Example (Next Page) ``` curl --request GET \ --url https://www.patreon.com/api/oauth2/v2/campaigns/$campaign_id/members?page%5Bcount%5D=5&page%5Bcursor%5D=03:eyj2ijoxlcjjijoinmy2ywmxmgutymu2ns00mtc5lweyodktmzkwzgmxmtfhmtq1iiwidci6iij9:1v2dmthw5w5reesle2scjmom \ --header "Authorization: Bearer $access_token" ``` ### Response Example (Last Page) ```json { "data": {}, "meta": { "pagination": { "total": 10, "cursors": { "next": null } } } } ``` **Note:** URL-encode square brackets as `%5B` and `%5D` when using raw cURL requests. ``` -------------------------------- ### HTTPS Request to Get Current User Source: https://docs.patreon.com/ This is the HTTPS request to fetch the current user's data. Ensure you pass the correct `access_token` from the user in your request. ```http GET https://www.patreon.com/api/oauth2/api/current_user ``` -------------------------------- ### Create Webhook Payload Source: https://docs.patreon.com/ Sample payload for creating a new webhook. Includes triggers, URI, and campaign relationship. ```json { "data": { "type": "webhook", "attributes": { "triggers": ["members:create", "members:update", "members:delete"], "uri": "https://www.example.com" }, "relationships": { "campaign": { "data": {"type": "campaign", "id": "12345"} } } } } ``` -------------------------------- ### GET /api/oauth2/v2/campaigns/{campaign_id}/posts Source: https://docs.patreon.com/#introduction Retrieves a list of all Posts associated with a specific Campaign, identified by its unique ID. This operation requires the `campaigns.posts` scope for authorization. ```APIDOC ## GET /api/oauth2/v2/campaigns/{campaign_id}/posts ### Description Get a list of all the Posts on a given Campaign by campaign ID. ### Method GET ### Endpoint /api/oauth2/v2/campaigns/{campaign_id}/posts ### Parameters #### Path Parameters - **campaign_id** (string) - Required - The ID of the campaign to retrieve posts from. ### Scope - campaigns.posts ```