Issues with patreon.js library

I’m currently making a discord.js bot that gives users more features if they are subscribed to one of my patreon tiers, however the documentation has done nothing but cause me headaches so far. I have even found a few errors in the documentation that resulted in me diving into the library files to see how they work. Here’s my latest problem.

const { patreon, jsonApiURL } = require('patreon')
const pledge_schema = require('patreon/schemas/pledge')
 
const patreonAPIClient = patreon(access_token)
const url = jsonApiURL(`/current_user`, {
  fields: {
    pledge: [...pledge_schema.default_attributes, pledge_schema.attributes.total_historical_amount_cents]
  }
})
patreonAPIClient(url, function(data) {

})
  .catch(console.log)

I’m using the above code from the Patreon js library, filled in my creator access_token, fixed the pledge_schema = require(... path (the documentation is incorrect), but I’m getting the following error:

pledge: [...pledge_schema.default_attributes,pledge_schema.attributes.total_historical_amount_cents]
                          ^

TypeError: pledge_schema.default_attributes is not iterable

I’m currently using Glitch to experiment with the library in (relatively) real-time before I implement it into my project. Any help would be appreciated.

Alright, looks like it’s a case of crappy documentation. Again. I ended up changing

pledge: [...pledge_schema.default_attributes, pledge_schema.attributes.total_historical_amount_cents]

to

pledge: [...pledge_schema.default.default_attributes, pledge_schema.default.attributes.total_historical_amount_cents]

after doing a bit of output-debugging to see what’s where, and that got it past the errors, but now I’m getting “BAD REQUEST” in the response body. I just used .catch(console.log) to catch said error, as shown in the main post.

{
  error: Body {
    url: 'https://www.patreon.com/api/oauth2/api/current_user?fields[pledge]=amount_cents,declined_since,created_at,pledge_cap_cents,patron_pays_fees,total_historical_amount_cents&',
    status: 400,
    statusText: 'BAD REQUEST',
    headers: Headers { _headers: [Object] },
    ok: false,
    body: PassThrough {
      _readableState: [ReadableState],
      readable: true,
      _events: [Object],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: true,
      allowHalfOpen: true,
      _transformState: [Object]
    },
    bodyUsed: false,
    size: 0,
    timeout: 0,
    _raw: [],
    _abort: false
  },
  response: Body {
    url: 'https://www.patreon.com/api/oauth2/api/current_user?fields[pledge]=amount_cents,declined_since,created_at,pledge_cap_cents,patron_pays_fees,total_historical_amount_cents&',
    status: 400,
    statusText: 'BAD REQUEST',
    headers: Headers { _headers: [Object] },
    ok: false,
    body: PassThrough {
      _readableState: [ReadableState],
      readable: true,
      _events: [Object],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: true,
      allowHalfOpen: true,
      _transformState: [Object]
    },
    bodyUsed: false,
    size: 0,
    timeout: 0,
    _raw: [],
    _abort: false
  }
}

I swear, this library is just full of bad/outdated documentation.

Various libraries have not been updated for some time due to there not being enough resources allocated to the api. JS library may not work as intended.

If your setup permits, you can use the PHP library as a backend for your app however, that library has been regularly updated:

It has working examples for various things, built-in functions to make other things easier.