# Commerical API 401ing?

**URL:** <https://discuss.dev.twitch.com/t/commerical-api-401ing/2323>\
**Category:** API\
**Created:** [May 27, 2015, 3:36am UTC](https://discuss.dev.twitch.com/t/commerical-api-401ing/2323 "2015-05-27T03:36:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bizkit047](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Bizkit047](https://discuss.dev.twitch.com/u/Bizkit047)\
**Post date:** [May 27, 2015, 3:36am UTC](https://discuss.dev.twitch.com/t/commerical-api-401ing/2323/1 "2015-05-27T03:36:51Z")

</div>

I’m trying to figure out how to use Twitch’s API from JS SDK to run commercials outside of the Dashboard in hopes it doesn’t log me out randomly (many have this problem). I’m a bit of an idiot with using this right now, but I can grab an Access Token just fine and do some things with it, but when I try to use the Token to run a commercial, it returns 401 for invalid Token & Scope. I definitely auth the token with channel\_commercial. If it isn’t scope, how can it be the auth token if it’s still valid for other API calls? Here is the code:

```auto
$('.runcommercial').click(function() {
          Twitch.api({method: 'channels/bizkit047/commercial', verb: 'POST'}, function(error, channel) {        
            });
        });
```

Also not entirely sure how long Access Tokens can stay valid. Should they still work if you close out of the page and come back later to do more API calls, or should a new token be requested every time the user wants to do something like run a commercial?

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [May 27, 2015, 7:36pm UTC](https://discuss.dev.twitch.com/t/commerical-api-401ing/2323/2 "2015-05-27T19:36:34Z")

</div>

The tokens should stay valid until a new one is requested or the application is disconnected from the account connection settings.

---

<div class="post-metadata">

**Author:** ![Bizkit047](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Bizkit047](https://discuss.dev.twitch.com/u/Bizkit047)\
**Post date:** [May 27, 2015, 9:09pm UTC](https://discuss.dev.twitch.com/t/commerical-api-401ing/2323/3 "2015-05-27T21:09:14Z")

</div>

That’s what I figured, so I’m somehow sending the request wrong I’d assume?

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [June 26, 2015, 9:09pm UTC](https://discuss.dev.twitch.com/t/commerical-api-401ing/2323/4 "2015-06-26T21:09:32Z")

</div>

Closed on June 26, 2015, 9:09pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
