API Returning Empty Attributes for Members

Been working with the v1 API for a bit and now am attempting to get some v2 calls working. The following command is connecting and returning some data, but the attributes object appears to be empty. Am I missing something in this nodejs function?

axios.get(`https://www.patreon.com/api/oauth2/v2/campaigns/${PATREON_CAMPAIGN_ID}/members`, {
    headers: { 
        Authorization: `Bearer ${PATREON_ACCESS_TOKEN}`,
        'Content-Type': 'application/x-www-form-urlencoded',
    },
}).then(resp => {
    console.info(resp.data.data);
});

Returns;

{
  attributes: {},
  id: '<member_id>',
  type: 'member'
}

You should make sure that axios or any other lib that you are using isnt interfering with anything or reformatting the JSON.

If that is certain, then its likely because you are not specifically requesting the fields that you want. Api v2 requires you to actively ask for the fields that you want instead of sending you a blob of JSON. So you should include those resources and relationships in the include= and, the related fields in the fields[…resource-here…]=.

Thanks, that’s definitely on the right track. I’m now able to get any ‘include’ parameter by added the parameters I’m wanting to the params list;

 await axios.get(`https://www.patreon.com/api/oauth2/v2/campaigns/${PATREON_CAMPAIGN_ID}/members`, {
    params: {
        'include': 'user'
    },
    headers: {
        Authorization: `Bearer ${PATREON_ACCESS_TOKEN}`,
        'Content-Type': 'application/x-www-form-urlencoded',
    },
}).then(resp => {
    ...
});

Returns;

{
  user: {
    data: { id: '<u_id>', type: 'user' },
    links: { related: 'https://www.patreon.com/api/oauth2/v2/user/<u_id>' }
  }
}

However, all combinations of fields[member], fields[tier], or fields[user] that I’ve tried result in a 400 error;

 await axios.get(`https://www.patreon.com/api/oauth2/v2/campaigns/${PATREON_CAMPAIGN_ID}/members`, {
    params: {
        'include': 'user',
        'fields[member]': 'patron_status'
    },
    headers: {
        Authorization: `Bearer ${PATREON_ACCESS_TOKEN}`,
        'Content-Type': 'application/x-www-form-urlencoded',
    },
}).then(resp => {
    ...
});

Going off what codebard said, and the API docs, and this → Get Patreon data based on discord user id · GitHub, the syntax seems correct. Any idea why the fields[member] addition causes bad request error?

Seems to be an Axios issue with bracket encoding If paramsSerializer is not specified, brackets are not encoded · Issue #3316 · axios/axios · GitHub

1 Like

Solution was to encode the URI;

encodeURI(`https://www.patreon.com/api/oauth2/v2/campaigns/${PATREON_CAMPAIGN_ID}/members?include=user&fields[member]=patron_status`)
1 Like