I am having trouble pulling the discord id of a pledging user from the req.body of the webhook.
How exactly do I structure the code to retrieve it properly. I’d like to declare it as a variable in node.js and use it later.
I am having trouble pulling the discord id of a pledging user from the req.body of the webhook.
How exactly do I structure the code to retrieve it properly. I’d like to declare it as a variable in node.js and use it later.
You receive the discord id, but you are unable to extract it from the return?
Correct. Im unsure if im using the incorrect objects. I have it parsing to Json.
If you see it in the return but its not being parsed, then the parser may be the reason. You can try manually decoding the return by using native functions instead of any parser lib. (If you are using one)
Here’s an actual members:pledge:create
webhook trigger, of which I can use to at least demonstrate the method used to call the specific value buried within:
{
"data": {
"attributes": {
"campaign_lifetime_support_cents": 0,
"currently_entitled_amount_cents": 100,
"email": "[EMAIL ADDRESS]",
"full_name": "First Last",
"is_follower": false,
"last_charge_date": null,
"last_charge_status": null,
"lifetime_support_cents": 0,
"next_charge_date": "2021-04-01T07:00:00.000+00:00",
"note": "",
"patron_status": "active_patron",
"pledge_cadence": 1,
"pledge_relationship_start": "2021-03-31T17:08:01.311+00:00",
"will_pay_amount_cents": 100
},
"id": "*-*-****-****-************",
"relationships": {
"address": {
"data": null
},
"campaign": {
"data": {
"id": "*****",
"type": "campaign"
},
"links": {
"related": "https://www.patreon.com/api/oauth2/v2/campaigns/*****"
}
},
"currently_entitled_tiers": {
"data": []
},
"user": {
"data": {
"id": "*****",
"type": "user"
},
"links": {
"related": "https://www.patreon.com/v2"
}
}
},
"type": "member"
},
"included": [{
"attributes": {
"created_at": "2021-01-12T02:01:27.000+00:00",
"creation_name": "STUFF OFFERED BY PATREON PAGE",
"discord_server_id": null,
"google_analytics_id": null,
"has_rss": false,
"has_sent_rss_notify": false,
"image_small_url": "[URL TO IMAGE]",
"image_url": "[URL TO IMAGE]",
"is_charged_immediately": false,
"is_monthly": true,
"is_nsfw": false,
"main_video_embed": null,
"main_video_url": null,
"one_liner": null,
"patron_count": 0,
"pay_per_name": "month",
"pledge_url": "/join/**************",
"published_at": "2021-01-12T02:05:13.000+00:00",
"rss_artwork_url": null,
"rss_feed_title": null,
"summary": "Creating stuff",
"thanks_embed": null,
"thanks_msg": null,
"thanks_video_url": null,
"url": "https://www.patreon.com/**************",
"vanity": "PATREON PAGE NAME"
},
"id": "6026224",
"type": "campaign"
}, {
"attributes": {
"about": null,
"created": "2017-12-01T05:39:59.000+00:00",
"first_name": "FIRST",
"full_name": "FIRST LAST",
"hide_pledges": false,
"image_url": "https://c10.patreonusercontent.com/3/XXXYYYZZZ/patreon-media/p/....jpg",
"is_creator": false,
"last_name": "LAST",
"like_count": 0,
"social_connections": {
"deviantart": null,
"discord": { <<<--------------------------------------- - Discord Info
"url": null,
"user_id": "*************"
},
"facebook": null,
"google": null,
"instagram": null,
"reddit": null,
"spotify": null,
"twitch": null,
"twitter": null,
"youtube": null
},
"thumb_url": "URL_TO_THUMBNAIL",
"url": "https://www.patreon.com/user?u=*****",
"vanity": null
},
"id": "123456666",
"type": "user"
}],
"links": {
"self": "https://www.patreon.com/api/oauth2/v2/members/****************"
}
}
I’ve made it more obvious where the discord data is gathered from. Here’s a more streamlined way of viewing it, thanks to VSCode and some JSON parsing extensions:
I am not sure of the exact syntax, but if I recall, javascript let’s you use either dot notation
or bracket notation
, so you should be able to access it and place it into a variable like this:
let variablename = json.included[1].attributes.social_connections.discord.user_id
Play with this kind of notation. it may take a couple of tries to get it correct.