useBits 401 Error

Hello. I am getting the following error: “POST https://api.twitch.tv/v5/bits/extensions/is-eligible/0001 401” when trying to use twitch.bits.useBits. Here “0001” is the SKU of my first product.

I am doing local testing in the developer rig and my code is as follows:

twitch.onAuthorized(function (auth) {
	twitch.bits.getProducts().then(function (products) {
       	twitch.rig.log(products);
	    $('#send').click(function () {

            if (!twitch.features.isBitsEnabled) { return twitch.rig.log(" bits not enabled") };

            twitch.bits.useBits(products[0].sku); //401 error
        });
	});
});

getProducts appears to be working perfectly well; the products are displayed as expected in the console. The bits enabled flag is passing. When I click on the “send” button the first time, the 401 error appears. On subsequent clicks, the error does not appear. In all cases (when the send button is pushed), no bits UI is popping up. As I understand it, a bits UI should pop up when I click the send button if everything is working correctly.

This would suggest that the channel you are testing on doesn’t allow bits to be used.

Or you are testing this in the rig (noting the presented of twitch.rig.log), and the rig doesn’t have a real user/balance to utilise useBits with

This post

has some guidance on testing bits in extensions.

1 Like

ah, so usebits just flat out will not work in the rig? I am using the rig, so I guess this is the problem

In the rig you would need to use

setUseLoopBack function

To “trigger” a success for test purposes when using useBits in the rig

1 Like