Pybossa : Get current user id through API

147 Views Asked by At

Is there a way to get the current user id of the person who is contributing on the tasks, through the Pybossa API?

Suppose I am one of the contributor for a project. I register on the Pybossa and contribute on the tasks. After this, I want to get my task-run information, and I don't know my user-id. Is there a way to get my task-run details, through the API? By going through api/taskrun, I get a lot of information of all the users, but I want to see just mine information. In short, I just need my user-id through API! That will do all the work.

3

There are 3 best solutions below

0
tomasran On

You can look at this and it also confused me: https://github.com/Scifabric/pybossa/issues/1484

0
Daniel Lombraña González On

This is a new feature ;-) We added it not so long ago. Right now you can get all your information in JSON format by querying this endpoint:

http://server/account//

This will work for any user, but if you are authenticated and you check your own username then, you will get all your info. From there you can get all your task runs without any problems. You have more info here http://docs.pybossa.com/en/latest/api.html?highlight=api#account-name

0
mikmak On

The solution is to query /account/profile which returns information about the currently logged in user.

$.ajax({
type: "GET",
url: "/account/profile",
contentType: "application/json",
dataType: "json",
success: function(data) {
  console.log(data.user.id);
},
error: function (xhr, textStatus, errorThrown) {
  console.log(xhr.responseText);
}
});