JSON data to determine if Patron Member is a Creator's Patreon or not

Hi,

Below is the sample json file for the Patron profile returned by the API:
{
“data”: {
“attributes”: {
“about”: null,
“created”: “2017-10-20T21:36:23+00:00”,
“discord_id”: null,
“email”: "corgi@example.com",
“facebook”: null,
“facebook_id”: null,
“first_name”: “Corgi”,
“full_name”: “Corgi The Dev”,
“gender”: 0,
“has_password”: true,
“image_url”: “https://c8.patreon.com/2/400/0000000”,
“is_deleted”: false,
“is_email_verified”: false,
“is_nuked”: false,
“is_suspended”: false,
“last_name”: “The Dev”,
“social_connections”: {
“deviantart”: null,
“discord”: null,
“facebook”: null,
“spotify”: null,
“twitch”: null,
“twitter”: null,
“youtube”: null
},
“thumb_url”: “https://c8.patreon.com/2/100/0000000”,
“twitch”: null,
“twitter”: null,
“url”: “https://www.patreon.com/corgithedev”,
“vanity”: “corgithedev”,
“youtube”: null
},
“id”: “0000000”,
“relationships”: {
“pledges”: {
“data”: []
}
},
“type”: “user”
},
“links”: {
“self”: “https://www.patreon.com/api/user/0000000
}
}

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”.

If you’re using php you can check out my Patreon PHP library which handles parsing response data for you: https://github.com/1f991/patreon-php

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.

1 Like

Hi @sam

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?

Thank you.

As noted in the documentation, some attributes are optional, on a Pledge for example:

// optional properties
"total_historical_amount_cents": <int>
"is_paused": <bool>
"has_shipping_address": <bool>

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_paused with the default data you’ll need to explicitly request is_paused, created_at, amount_cents, declined_since, has_shipping_address etc.

You can find an explanation of how to request optional data in the documentation here: https://docs.patreon.com/#requesting-specific-data

My library builds a request URL containing each property of the entity, you can see how it does that here: https://github.com/1f991/patreon-php/blob/master/src/Patreon/Resources/Resource.php#L128

Let me know if you need any other information :slight_smile:

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?

Yeah you need a client id…

For my meteor js app…I did something like this…

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)