1
votes

I'm unable to fetch anything from the Wakatime API, and I don't know what is wrong.

The Documentation states:

Authentication to the API can be done using HTTP Basic Auth or by adding your api key as a query parameter in your request url like ?api_key=XXXX. Using HTTP Basic Auth, your username is your API key base64 encoded. Your password is not needed to authenticate.

For example, when using HTTP Basic Auth with an API key of 12345 you should add this header to your request:

Authorization: Basic MTIzNDU=

I'm using HTTParty to handle the request:

https://wakatime.com/api/v1/users/theminijohn?api_key=XXX

HTTParty.get('https://wakatime.com/api/v1/users/@theminijohn?api_key=XXX')

But this returns:

{
  "error": "Not found"
}

What am I doing wrong?

1

1 Answers

2
votes

You need to provide user id in API endpoint, not username.

Spec:

GET users/:user

Means:

GET users/:user.id

This works:

https://wakatime.com/api/v1/users/f0fbed96-0c45-4d01-89e4-6a595a23299b?api_key=XXXX

I've got user ID from:

https://wakatime.com/api/v1/users/current?api_key=XXX