Simple Javascript - Member Address Attribute is blank

Hey everyone. I’m really rusty with some of this coding using javascript from scratch since I can’t employ any node packages. I’m building a javascript function because the Zapier integration fails to pull new pledge addressee information on the webhook.

When I run this GET request, the attributes for the address are empty. Does anyone know why?

var url = 'https://www.patreon.com/api/oauth2/v2/members/' + inputData.patreonID + '?include=address'
const login = await fetch(url, {
  headers: {
      'Authorization': 'Bearer hidden',
      'Content-Type': 'application/x-www-form-urlencoded'
    },
  }
);
const body = await login.json();
return {output: body.included[0].attributes};

Using ARC for Chrome the output looks like:

{
"data": {
"attributes": {},
"id": "01ba8fd2-9d8c-blah",
"relationships": {
"address": {
"data": {
"id": "112233",
"type": "address"
},
"links": {
"related": "https://www.patreon.com/api/oauth2/v2/address/112233"
}
}
},
"type": "member"
},
"included": [
  {
"attributes": {},
"id": "112233",
"type": "address"
}
],
"links": {
"self": "https://www.patreon.com/api/oauth2/v2/members/01ba8fd2-9d8c-blah"
}
}

This is just a guess, but I’m assuming the access token when creating a new client and api key doesn’t have access to this scope. So now I’m trying to go the Oauth2 route. But I have no idea how I’m supposed to make a function running in a server login to the patreon page to get the code response.

You may try specifically asking for address in the include. Check out this call in the resource documentation:

(the call is at the right, along with example return).

You will see that the address is specifically asked as an include. And yes, the scope must be asked while creating the token.

Hi @codebard. Thanks for taking a minute to help me out. I believe I am asking for the address in the include in my reference above. I’ve also used the documentations entire GET request and it still doesn’t populate the address.

So this is where I stand.
The current Patreon OAuth2 API requires you to use the /authorize endpoint. This REQUIRES user interaction to manually input username and passsword info. Looking at the OAuth docs, I tried using the client-credentials method but i’m getting a 405 METHOD NOT ALLOWED response.

Unfortunately, it doesn’t look like the Creator’s Access Token has the members.address scope defined when creating a new app using the Patreon API. That’s the only logical explanation I can think how this is working because the addresses attributes are missing.

I’m not sure how I can create make this successfully work running in a zapier function where no user interaction will be capable. Are any there pointers on how to do the OAuth2 flow programmatically?

The Patreon docs state “The client creator’s access token will automatically have all V2 scopes associated with it.” So I’m officially at a loss. I’m using the Creators Access Token as my Bearer token and I cannot retrieve the mailing address for any user. If there are any suggestions, I’m willing to try anything. Thanks

Is your client already v2?

@codebard yes, i created the client using API v2

This may be because you are directly requesting the member resource and address is not an attribute of it. But it is a relationship.

What happens if you use something like:

var url = ‘https://www.patreon.com/api/oauth2/v2/members/’ + inputData.patreonID + ‘?include=address.line_1’

Does the first line of street address come in?

@codebard I’m getting a 400 bad request saying that’s an invalid parameter on include. I tried all the attributes individually but none work. :frowning:

{
	"errors": [{
		"code": 1,
		"code_name": "ParameterInvalidOnType",
		"detail": "Invalid parameter for 'include' on type member: ['address.city'].",
		"id": "df527b9d-d88d-4848-9be7-48a716a0fd86",
		"status": "400",
		"title": "Invalid value for parameter 'include'."
	}],
}

FIGURED IT OUT!! The documentation is incorrect. There are additional parameters that are missing to collect the fields!!

https://www.patreon.com/api/oauth2/v2/members/+ inputData.patreonID + ?include=address&fields%5Baddress%5D=addressee,line_1,line_2,city,state,postal_code,country
1 Like

The fields must be specially asked in includes, this is stated early in the documentation. But it seems it is easy to miss.

I thought you were getting a scope/auth error so i went on that tangent. But if you have figured it out, great - good luck with your integration.