Open darkpixel opened 8 years ago
Temp work-around:
var toggl = new api({apiToken: process.env.TOGGL_API_KEY});
var req = {
method: 'GET',
auth: {}
};
req.auth[process.env.TOGGL_API_KEY] = 'api_token';
toggl.apiRequest('/api/v8/me', req, function(err, authdata) {
if (err) {
debug(err);
} else {
// do whatever
}
});
@darkpixel I'm kind of late here, sorry. Is it still actual?
It may be, but I switched jobs and no longer have to provide reports based on Toggl data. ;)
I can confirm that using the authenticate(callback)
method does still return the same error that @darkpixel mentioned: Error: No need to authenticate thus you use apiToken
.
However, using the getUserData(options, callback) method will give you your user id in the JSON response object under the id
property like so:
const config = require('./config')
const TogglClient = require('toggl-api')
const toggl = new TogglClient({apiToken: config.togglToken})
toggl.getUserData({}, (err, userData) => {
if (err) console.log(err)
console.log(userData.id)
})
EDIT: It appears PR #11 should fix the authenticate(callback)
method I referred to.
If I use curl to authenticate using an API token to the Toggl API, it returns a blob of JSON that includes my user ID.
If I authenticate using node-toggl-api and a username and password and call the
authenticate()
method, I get a blob of data back with my user ID.But if I call
authenticate()
when using an API Token, I get an errorError: No need to authenticate thus you use apiToken
and I don't see a way to get my user ID. Am I missing something?