Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get my user ID? #8

Open
darkpixel opened this issue Oct 12, 2016 · 4 comments
Open

Get my user ID? #8

darkpixel opened this issue Oct 12, 2016 · 4 comments

Comments

@darkpixel
Copy link

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 error Error: No need to authenticate thus you use apiToken and I don't see a way to get my user ID. Am I missing something?

@darkpixel
Copy link
Author

darkpixel commented Oct 12, 2016

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
  }
});

@estliberitas
Copy link
Member

@darkpixel I'm kind of late here, sorry. Is it still actual?

@darkpixel
Copy link
Author

It may be, but I switched jobs and no longer have to provide reports based on Toggl data. ;)

@4lch4
Copy link

4lch4 commented Nov 28, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants