# Accessing Username of Requestor

If you want to access the `username` or `id` of the requesting user from within the `doLookup` `onDetails` or `onMessage` method you can easily do this by accessing the `_request` property on the `options` variable passed into the respective method. The `_request` property contains a `user` object which includes a `username` and `id` property.

The structure of the `_request` property is as follows

```javascript
// _request property on the `options` variable
{
    _request: {
        user: {
            username: 'admin', //username of the requesting user
            id: 5 // user if of the requesting user
        }
    }
}
```

{% hint style="info" %}
The `id` property is a unique internal identifier used by Polarity to track the user.  The `id` is a `numeric` value and does not change even if the user updates their `username`.
{% endhint %}

## doLookup Example

Here is an example for how you would access the `username` and `id` of the requesting user from within the `doLookup` method.

{% code title="integration.js" %}

```javascript
function doLookup(entities, options, cb){
    let username = options._request.user.username;
    let userId = options._request.user.id;
    
    // make use of `username` and/or `userId`
    ...
```

{% endcode %}

## onDetails Example

{% code title="integration.js" %}

```javascript
function onDetails(lookupResult, options, cb){
    let username = options._request.user.username;
    let userId = options._request.user.id;
    // use `username` and `userId` as required
    ...
```

{% endcode %}

## onMessage Example

{% code title="integration.js" %}

```javascript
function onMessage(payload, options, cb){
    let username = options._request.user.username;
    let userId = options._request.user.id;
    // use `username` and `userId` as required
    ...
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.polarity.io/integrations/recipes/accessing-username-of-requestor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
