# How i can retrieve the user id throught username ?

**URL:** <https://community.ofelia.com/t/how-i-can-retrieve-the-user-id-throught-username/7226>\
**Category:** Q&A\
**Created:** [19 April 2016 14:28 UTC](https://community.ofelia.com/t/how-i-can-retrieve-the-user-id-throught-username/7226 "2016-04-19T14:28:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [19 April 2016 14:28 UTC](https://community.ofelia.com/t/how-i-can-retrieve-the-user-id-throught-username/7226/1 "2016-04-19T14:28:57Z")

</div>

Most of the resources of Bonita API requires the id of user. In order to retrieve the user information , first of all i’m using a mysql query to retrieve the id of user and afterwards i call the API, so , is there a way to retrieve the user information using the username instead of the user id.

i’m using this code , it’s work good, but no is the best way:

```
  $query = mysqli_query($conexio_bd, "SELECT id from user_ where userName='".$usuari."'");
        while($row=mysqli_fetch_assoc($query)){
        			
         $baseURL = 'http://localhost:8080/bonita/';
        curl_setopt($conexio,CURLOPT_URL,$baseURL.'API/bpm/humanTaskp=0&c=100&f=state%3dready&f=user_id%3d'.**.$row['id']**);

.
.`

```

Thanks

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [19 April 2016 15:15 UTC](https://community.ofelia.com/t/how-i-can-retrieve-the-user-id-throught-username/7226/2 "2016-04-19T15:15:34Z")

</div>

Simply put No,

the reason user\_id is used is the API is written like this, and I suspect basic SQL Normalization techniques come into it somewhere.

The other reason I wouldn’t do this this user\_id is anonymous, consider the following

…API/bpm/humanTaskp=0&c=100&f=state%3dready&f=user\_id=996

Who is user\_id 996? No way of telling.

Whereas

…API/bpm/humanTaskp=0&c=100&f=state%3dready&f=user\_name=Jane\_Kotton

means anyone scanning the network for data flows will know that Jane Kotton is doing something…What we don’t know but that’s not the point…depending on the business this could be very important…

I think your code is actually not bad.

regards  
Seán

_PS: If this reply answers your question, please mark a resolved._

---

<div class="post-metadata">

**Author:** ![richard.vigniel](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@richard.vigniel](https://community.ofelia.com/u/richard.vigniel)\
**Post date:** [25 April 2016 12:31 UTC](https://community.ofelia.com/t/how-i-can-retrieve-the-user-id-throught-username/7226/3 "2016-04-25T12:31:26Z")

</div>

Hi,  
a simple search on userName will give you the user detail:  
API/identity/user?p=0&c=10&o=userName&s=Jane\_Kotton

regards,  
Richard

---

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [25 April 2016 22:44 UTC](https://community.ofelia.com/t/how-i-can-retrieve-the-user-id-throught-username/7226/4 "2016-04-25T22:44:00Z")

</div>

Ok, thanks , now i’m trying to optimize my code and i have done simple test in order to know what the way is the bes in order to minimize the delay. Now in some calls to the Api rest , i have put the delay function because i investigated and i have found that the API response is delayed more than php code so is normal?
