# Compute user fit score

## Why Fit Score Matters

&#x20;A user with a **moojoᴵᴰ** accumulates hundreds of credentials over their lifetime by interacting with various apps and AI agents. These credentials remain private, secure, and inaccessible to any third-party application.

To leverage these credentials for personalization and targeting, you can request **moojoᴵᴰ** to compute a fit score for a specific segment.

The fit score is calculated using a structured set of rules, conditions, and weighted parameters. \
**This process ensures precise targeting while maintaining strict user privacy and data security.**

## Defining the Fit Score Conditions

A fit score condition consists of an array of rules and corresponding weights:

```
[
    {
        "rule": {
            "slug": "groceries-expenses",
            "conditions": {...}
        },
        "weight": 2
    },
    {
        "rule": {...}, "weight": 3
    },
    {
        "rule": {...}, "weight": 1
    }
    ...
    ...
    ...
]
```

### Rules conditions

| Condition    | Supported types | Description                                          |
| ------------ | --------------- | ---------------------------------------------------- |
| `eq`         | string, uint    | Equals (==)                                          |
| `contains`   | string          | A substring that is contained within the full string |
| `startsWith` | string          | A prefix contained within the field string           |
| `gt`         | uint            | Greater than (>)                                     |
| `gte`        | uint            | Greater than or equals (>=)                          |
| `lt`         | uint            | Less than (<)                                        |
| `lte`        | uint            | Less than or equals (<=)                             |

### Condition example

```
[
    {
        "rule": {
            "slug": "groceries-expenses",
            "conditions": {
              currency: {contains:'USD'},
              expense: {gte: 400, lt:1000}
            }
        },
        "weight": 2
    }
]
```

## Compute Fit Score

<mark style="color:green;">`POST`</mark> `/api.moojo.id/user/vault/compute-fit-score`

**Headers**

| Name          | Value                                                                                                             |
| ------------- | ----------------------------------------------------------------------------------------------------------------- |
| Content-Type  | `application/json`                                                                                                |
| x-api-key     | Your API KEY as provided by Moojo                                                                                 |
| Authorization | <p><code>Bearer {{USER\_TOKEN}}</code><br><br>Retrieve the user token using one of the authentication methods</p> |

**Body**

| Name    | Type             | Description |
| ------- | ---------------- | ----------- |
| `query` | array of objects |             |

**Request example**

{% tabs %}
{% tab title="body" %}
{% code overflow="wrap" %}

```json
{
    "query": [
        {
            "rule": {
                "slug": "big-spender"
            },
            "weight": 3
        },
        {
            "rule": {
                "slug": "groceries-expenses",
                "conditions": {
                  currency: {contains:'USD'},
                  expense: {gte: 400}
                }
            },
            "weight": 2
        }
    ]
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

**Response example**

{% tabs %}
{% tab title="200" %}

```json
{
    "status": "success",
    "traceId": "0bb43125-1cf4-466e-b1bd-f614a2f60000",
    "data": {
        "score": 0.8
    }
}
```

{% endtab %}
{% endtabs %}
