• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN How to use the HTTP API in an script?

Status
Not open for further replies.

Rexima

Member
Hey,

I want to use the HTTP API in my own custom script.

HTML:
sinusbot.http({
                method: 'GET',
                url: 'http://127.0.0.1:8087/api/v1/bot/login',
                timeout: 6000,
                data:
                '{"username":"dev", "password":"dev", "botId":"149dcf02-2a06-4a79-9150-75c972ed8276"}'
              },
              function(error, response)
              {

                   
                    //var Response = JSON.parse(response.data);
                    sinusbot.log("Response: "+response.data);
              });

And this doesnt work. i got no valid response
 

Rexima

Member
Okay thank you. Sorry i found everything i need on the script api.
But one thing is missing: How can i retrieve informations about a currently playing Youtube Playlist?

What i cant get, is the duration of the current playing yt music.
And the Event "trackEnd" gots triggered, but the track is playing.
 

irgendwr

no longer active, "retired" staff member
is awesome!
V.I.P.
is uber awesome!
Contributor
Insider
Okay thank you. Sorry i found everything i need on the script api.
But one thing is missing: How can i retrieve informations about a currently playing Youtube Playlist?

What i cant get, is the duration of the current playing yt music.
And the Event "trackEnd" gots triggered, but the track is playing.
I still don't understand why you want to use the HTTP-api, you can do most things with the scripting api (Doc: Webinterface > Help > Scripting)
(the new one has even more stuff --> Doc: https://www.sinusbot.com/docs/scripting/ (Requires v0.9.16) )

Code:
var engine = require('engine');
var media = require('media');
var event = require('event');

event.on('trackEnd', function(track, callback) {
    // do stuff
    engine.log('Track ' + track.title() + ' stopped playing');
});

// get the currently playing track:
var currTrack = media.getCurrentTrack();

But getting the duration is currently only possible via the HTTP-api I think:
POST to http://127.0.0.1:8087/api/v1/bot/i/:instanceId/status
and take a look at "queueLen" & "position"

EDIT/UPDATE: Now you can get the duration of a track with: track.duration()
 
Last edited:

vincolus

Donor
is awesome!
Contributor
Insider
Example Scenario: I need to log in and retreive the token, which I then pass from my script to my webinterface via url parameters. Because I will need the token for most requests.
Does this make sense or is there an easier way?
 
Status
Not open for further replies.
Top