Closed richardogcc closed 1 year ago
endpoints.CHANNEL_POINTS
is an object, that contains various endpoints that have something to do with Twitch Channel Points, such as endpoints.CHANNEL_POINTS.CREATE_CUSTOM_REWARD
, and should not be used as an Endpoint.
(Sorry for my bad english)
This is correct. Has it solved your issue?
How can I see the existing point rewards?
I've tried with ezTwitchClient.api('get', endpoints.CHANNEL_POINTS.GET_CUSTOM_REWARD_REDEMPTION).then(console.log).catch(console.error);
and also give me an error.
Which error do you get?
data: {
error: 'Bad Request',
status: 400,
message: 'Missing required parameter "broadcaster_id"'
}
EZTwitch doesn't take care of the needed params given by the Twitch API. Please check out the reference to see which parameters you need. In your case, to add the parameters, just do it like so:
ezTwitchClient.api('get', `${endpoints.CHANNEL_POINTS.GET_CUSTOM_REWARD_REDEMPTION}?your_param=xyz&other_param=abc`)
Replace your_param and other_param, as it's only a placeholder.
I hope I could help you :)
There's no way to get broadcaster id easily with EZTwitch?
Not yet. Usually you just fetch the user using the login (reference). I use a chrome extension for that because it's faster, here's a link.
If you like, I'll add a feature like that to eztwitch soon.
I will give it a try, thanks!
No problem, hope it helps! :)
it should be
const broadcasterId = await ezTwitchClient.api('get', endpoints.USERS.GET.USER + "?name=<name>")
.then(data=>encodeURIComponent(data.user_id))
.catch(console.error);
await ezTwitchClient.api('get', endpoints.CHANNEL_POINTS.GET_CUSTOM_REWARD_REDEMPTION + "?broadcaster_id=" + broadcasterId).then(console.log).catch(console.error)
it should be
const broadcasterId = await ezTwitchClient.api('get', endpoints.USERS.GET.USER + "?name=<name>").catch(console.error); await ezTwitchClient.api('get', endpoints.CHANNEL_POINTS.GET_CUSTOM_REWARD_REDEMPTION + "?broadcaster_id=" + broadcasterId).then(console.log).catch(console.error)
Nope, you're putting the user data as a param here 🤔
You could simplify it with a helper function:
async function getUserId(name, api) {
return api.api('get', endpoints.USERS.GET.USER + "?name=" + encodeURIComponent(name)).then(user=>user.id).then(id=>encodeURIComponent(id));
}
await ezTwitchClient.api('get', endpoints.CHANNEL_POINTS.GET_CUSTOM_REWARD_REDEMPTION + "?broadcaster_id=" + await getUserId('channel_name'))
.then(console.log)
.catch(console.error)
You don't need to encode the url component as the id is just a set of numbers without spaces etc.
i know, just good practice
Good point.
@ArsDankeZik you might close this if we could help you :) Otherwise I'll close this in a week or so (I'll probably forget lol) if nothing happens to that moment. We're always happy to help and we hope you'll have fun using EzTwitch. If there's something to optimize, please tell us. Thanks ^^
You could simplify it with a helper function:
async function getUserId(name, api) { return api.api('get', endpoints.USERS.GET.USER + "?name=" + encodeURIComponent(name)).then(user=>user.id).then(id=>encodeURIComponent(id)); } await ezTwitchClient.api('get', endpoints.CHANNEL_POINTS.GET_CUSTOM_REWARD_REDEMPTION + "?broadcaster_id=" + await getUserId('channel_name')) .then(console.log) .catch(console.error)
@FishingHacks That works better than the solution you posted before that 👍
I forgot it back then - I will close this now.
Client-ID and Authorization removed for obvious reasons.
On calling any endpoint
ezTwitchClient.api('get', endpoints.CHANNEL_POINTS).then(console.log).catch(console.error)
returns next error:utils
is working fine.