Closed Anaerin closed 7 years ago
The utils.merge
function overwrites options.method
with "GET"
for some reason. I suggest requiring the request module outright for now. You could also use the method overwrite option:
{
/* ... */
qs: {
_method: 'put'
},
/* ... */
}
The method overwrite doesn't work, unfortunately, as the request body is ignored/removed. Fortunately, going around works just fine:
const Request = require("request"); // Temporary, to work around a bug in tmi.js
putAPIValue(url, data, callback) {
var requestObj = {
url: url,
method: "PUT",
json: true,
headers: {
Accept: "application/vnd.twitchtv.v3+json",
'Client-ID': this.oAuth.clientID,
Authorization: "OAuth " + this.oAuth.accessToken
},
body: data
}
// The following call is broken right now: https://github.com/tmijs/tmi.js/issues/166
// var request = this.tmi.api(requestObj, callback);
// Use request directly instead, until it's fixed.
var request = Request(requestObj, callback);
}
You'll be making a GET request so put your values in qs with the _method
override.
client.api({
baseUrl: 'https://api.twitch.tv/kraken/',
url: 'channels/alca',
headers: {
Accept: 'application/vnd.twitchtv.v3+json',
'Client-ID': '...',
Authorization: 'OAuth ...'
},
qs: {
channel: {
status: 'Playin\' some CS:GO! or whatever',
game: 'Counter-Strike: Global Offensive',
delay: 0,
channel_feed_enabled: true
},
_method: 'put'
}
}, callback);
Has this actually been fixed, because I don't see a checkin that deals with it. And in some cases (doing OAuth Authentication, for instance), using the QueryString workaround is undesirable, as the POST sends the client_secret. So rather than using this barely-documented workaround, it would be very nice if it worked as expected.
I am using the client.api() functionality, but it appears PUT requests aren't working as expected.
I'm sending as my request object:
Which, according to the documentation for the request library, should execute a PUT of a json-stringified channel object to the API.
And I'm getting in response:
Which contains the previous details, not the newly updated ones.
Any suggestions?
Server configuration