> For the complete documentation index, see [llms.txt](https://docs.eximee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/skrypty-scriptservice/api-skryptow/pobranie-kontekstu-uzytkownika.md).

# Retrieving the context of the logged-in user

The API allows retrieving the context of the user currently filling out the form. The context describes users logged in on the form, in the Dashboard application or client applications integrated with the Eximee system, as well as information about the session of a user who is not logged in.

{% hint style="warning" %}
Functionality available from platform version: 4.737.0

The functionality works on requests launched in the webforms application.
{% endhint %}

***

## API

```typescript
interface User {
    v1: {
        getIdentity(): UserIdentity
    }
}


interface UserIdentity {
    userId(): string,
    roles(): string[],
    firstName(): string,
    lastName(): string,
    type(): 'client'|'employee'|'otp',
    system(): string
}
```

{% hint style="info" %}
Fields: firstName, lastName, roles depend on the authentication integration method used in the implementation.

Most often, these fields are available only for Employee-type authentication (employee) in Dashboard systems or Client systems integrated with Eximee.
{% endhint %}

#### Execution context

The API is available from the object `api.user.v1` and works in the form context.

It supports users working with the form:

* logged in through the Web channel in accordance with the implementation integration,
* logged in through the Dashboard application,
* logged in through authorization of integrated implementation systems,
* not logged in within the basic scope of user distinguishability.

***

## Usage examples

### Retrieving user data

```typescript
function callService(context) {
    const identity = api.user.v1.getIdentity();
    Logger.info("Get user identity: {}", identity)
    return [{
        'userId': identity.userId,
        'firstName': identity.firstName,
        'lastName': identity.lastName,
        'type': identity.type,
        'system': identity.system,
    }];
} 
```

### Example usage in a script

```typescript
function callService(context) {
    const AVAILABLE_ROLES = ["EXIMEE_BROKER_MORTGAGE_DASHBOARD"]
    let identity = api.user.v1.getIdentity()
    let roles = identity.roles
    Logger.info("simpleMortgageExecutionPermissionVerify roles: {}", roles)

    if (!roles) {
        throwBusinessError("error_page_default-*", "No permission to start the process")
    }
    let isAvailableRole = roles.some(role => AVAILABLE_ROLES.includes(role.toUpperCase()))

    if (!isAvailableRole) {
        throwBusinessError("error_page_default-*", "No appropriate role to start the process")

    }
    let userId = identity.userId
    return [{ userId }];

    function throwBusinessError(textcontentName, errorDescription) {
        const builder = context.getErrorPageDefinitionBuilder();
        builder.bodyTextContent(textcontentName);
        builder.msg(errorDescription);
        context.throwBusinessException(builder);
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/logika-biznesowa/scriptcode/skrypty-scriptservice/api-skryptow/pobranie-kontekstu-uzytkownika.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
