# Changing stream title with python

**URL:** <https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966>\
**Category:** API\
**Created:** [October 3, 2023, 10:59pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966 "2023-10-03T22:59:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sea\_echols](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sea_echols/32/27259_2.png) [@sea\_echols](https://discuss.dev.twitch.com/u/sea_echols)\
**Post date:** [October 3, 2023, 10:59pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/1 "2023-10-03T22:59:52Z")

</div>

Hello everyone! I am making a twitch bot that would change the title and/or game of my streams. I have been following the documentation and some threads already here and have gotten all the way up to getting an access token. However, the issue now lies with making a request and actually changing the title by using the following code:  
channelEDIT\_url = “[https://api.twitch.tv/kraken/channels/](https://api.twitch.tv/kraken/channels/)” + “MY\_CHANNEL\_NAME”  
headers =   
{  
‘Accept’: ‘application/vnd.twitchtv.v5+json’,  
“Client-ID”: “MY\_BOTS\_CLIENT\_ID”,  
“client\_secret” : “MY\_BOTS\_CLIENT\_SECRET”,  
“Authorization”: "OAuth " + (access token from [https://id.twitch.tv/oauth2/authorize](https://id.twitch.tv/oauth2/authorize)),  
“Content-Type”: “application/json”,  
“scope” : “channel\_editor”  
}  
data = {“channel[status]”: “NEW TITLE”}  
response = requests.post(url=channelEDIT\_url, headers=headers, params=data)

The code doesn’t crash at least lol, but it still does not change the title of my stream or do anything… Would anybody know any fixes? Thank you for your time!

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2023, 11:02pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/2 "2023-10-03T23:02:38Z")

</div>

> [@sea\_echols](#):
>
> channelEDIT\_url = “[https://api.twitch.tv/kraken/channels/”](https://api.twitch.tv/kraken/channels/%E2%80%9D) + “MY\_CHANNEL\_NAME”

This is horribly oudated. Kraken is long dead

> [@sea\_echols](#):
>
> ‘Accept’: ‘application/vnd.twitchtv.v5+json’,

Don’t need this header is kraken specific

> [@sea\_echols](#):
>
> Would anybody know any fixes? Thank you for your time!

You need to update to use the new URL and payload

> **[Reference](https://dev.twitch.tv/docs/api/reference/#modify-channel-information)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

URL: `https://api.twitch.tv/helix/channels?broadcaster_id=YOURID` (not the username)  
Method: `PATCH`  
Headers: Authorization is prefixed with `Bearer ` not `OAuth `  
Payload: updated to match documented

---

<div class="post-metadata">

**Author:** ![sea\_echols](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sea_echols/32/27259_2.png) [@sea\_echols](https://discuss.dev.twitch.com/u/sea_echols)\
**Post date:** [October 3, 2023, 11:26pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/3 "2023-10-03T23:26:50Z")

</div>

It didn’t seem to work am I missing something? here is the code now:  
channelEDIT\_url = “[https://api.twitch.tv/helix/channels?broadcaster\_id=](https://api.twitch.tv/helix/channels?broadcaster_id=)” + “CHANNEL\_ID\_NUMERIC”  
data =   
{  
“Client-ID”: “BOT\_CLIENT\_ID”,  
“Authorization”: "Bearer " + ACCESS\_TOKEN,  
“Content-Type”: “application/json”,  
“title” : “TEST TITLE”  
}  
response = requests.patch(channelEDIT\_url, json=data)

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2023, 11:31pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/4 "2023-10-03T23:31:27Z")

</div>

Becuase you put headers and data into the same place as JSON data.

So that would of raised a 4xx code

```auto
headers = {
“Client-ID”: “BOT_CLIENT_ID”,
“Authorization”: "Bearer " + ACCESS_TOKEN,
“Content-Type”: “application/json”,
}
data = {
    'title': 'New Title'
}

requests.patch(“https://api.twitch.tv/helix/channels?broadcaster_id=” + “CHANNEL_ID_NUMERIC”, headers=headers, json=data)

```

Should work (untested I don’t do python well)

---

<div class="post-metadata">

**Author:** ![sea\_echols](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sea_echols/32/27259_2.png) [@sea\_echols](https://discuss.dev.twitch.com/u/sea_echols)\
**Post date:** [October 3, 2023, 11:39pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/5 "2023-10-03T23:39:34Z")

</div>

still no unfortunately 😕 sorry I’m just used to python it’s the first programming language I’ve learned so it’s just cemented in my head.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [October 3, 2023, 11:49pm UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/6 "2023-10-03T23:49:03Z")

</div>

This worked for me.  
Got the expected 204 with user token generated with the needed scope

```py
import requests

client_id = ''
access_token = ''
streamer_id = ''

headers = {
    'Client-ID': client_id,
    'Authorization': 'Bearer ' + access_token,
    'Content-Type': 'application/json'
}
data = {
    'title': 'testing a title change'
}

upd = requests.patch('https://api.twitch.tv/helix/channels?broadcaster_id=' + streamer_id, headers=headers, json=data)

print(upd);

```

Response:

`<Response [204]>`

---

<div class="post-metadata">

**Author:** ![sea\_echols](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/sea_echols/32/27259_2.png) [@sea\_echols](https://discuss.dev.twitch.com/u/sea_echols)\
**Post date:** [October 4, 2023, 12:34am UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/7 "2023-10-04T00:34:48Z")

</div>

I figured out the issue, the PATCH request helped me figure out it was the wrong type of access token i am running a bot of my laptop not a server so i had a different type of access code ran and it solved it thanks so much for your help!

---

<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:** [November 3, 2023, 12:35am UTC](https://discuss.dev.twitch.com/t/changing-stream-title-with-python/47966/8 "2023-11-03T00:35:45Z")

</div>

Closed on November 3, 2023, 12:35am UTC

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