How do I check if the Patron is a Patreon of my Creator Page?
I noticed that there is “data” inside “pledges” which is inside “relationships”.
Do I check for my particular Patreon ID number inside data.relationships.pledges.data and if my Patreon ID is inside that array then that means that person has pledged to my Creation?
Patreon use the JSON API standard, which separates out entity data from relationships — this means the entity data only needs to be included in the response once even if the entity appears as a relationship many times.
You can try parsing it yourself but your best bet is to find a JSON API client library that will do it for you. What language are you using? Searching “language JSON api client” will yield good results, e.g: “nodejs JSON api client”.
The response you receive will either contain no pledge or one pledge, as your api key is only able to access pledge data to your campaign[1]. You can determine if a user is an active patron of your campaign if there is a value in the pledge field and that pledge is not declined, deleted or paused.
You can check the Entities in my library above to see the logic for determining pledge state (even if you’re not using PHP, the logic will be helpful for understanding how Patreon works.)
[1] unless Patreon have granted you multi-campaign access but that is not available unless you explicitly request it.
Thank you for the reply.
I have checked your php library “patreon-php”.
I have found this:
/**
* An active pledge is not paused and is not currently declined.
* Note: a pledge can be active even if the patron hasn't been charged yet
* if the campaign does not charge upfront.
*
* @return bool
*/
public function isActive(): bool
{
return $this->declined_since === null && $this->is_paused !== true;
}
I have compared this to the JSON I received for the pledge result:
var pledge = store.findAll(“pledge”)
console.log(‘pledge.length’, pledge.length)
console.log(‘pledge’, pledge)
console.log(‘pledge[0].id’, pledge[0].id)
console.log(‘pledge[0].creator’, pledge[0].creator)
console.log(‘pledge[0].patron’, pledge[0].patron)
I can see the declined_since (key/value) but I can’t find the is_paused key/value pair.
In pledge[0].patron though I do see is_deleted and is_suspended.
Which variables should I check to make sure the Patron is an active supporter of my project?
You must request these attributes explicitly to have them included in the response. However, a very important caveat is that when you explicitly request any attribute you must explicitly request every attribute you wish to be included. Therefore, if you would like to have access to is_pausedwith the default data you’ll need to explicitly request is_paused, created_at, amount_cents, declined_since, has_shipping_address etc.
Hey, I have a question about it.
My bot is written on Node.js, and I have been trying to get the Patrons of a Creator for a while.
I don’t know what to do, nor I know which link I should send an API Request to.
I would love if someone displayed me an example of how would it be on Node.js as I have no idea as of right now. I have checked the API Documentation but I really don’t know what to use and what to do.
Thank you.
Edit: Would I need to get an access token or anything to access that? If so, how do I get it?
var url = 'https://www.patreon.com/oauth2/authorize?response_type=code&client_id=' + clientid +'&redirect_uri=' + redirecturl
// this function can fire onclick handler for any DOM-Element
function fireClickEvent(element) {
var evt = new window.MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
element.dispatchEvent(evt);
}
// this function will setup a virtual anchor element
// and fire click handler to open new URL in the same room
// it works better than location.href=something or location.reload()
function openNewURLInTheSameWindow(targetURL) {
var a = document.createElement('a');
a.href = targetURL;
fireClickEvent(a);
}
function openNewTabOrNewWindow(targetURL) {
var a = document.createElement('a');
a.href = targetURL;
a.target = '_blank'; // now it will open new tab/window and bypass any popup blocker!
fireClickEvent(a);
}
openNewURLInTheSameWindow(url)