# Profile

When a user is registered, a profile is created automatically. The user's profile contains personal information about the user and the device. For accurate measurements, it's important to keep this profile up-to-date.

{% hint style="info" %}
**App Development Best Practice**

Make sure to regularly update the profile information, preferably after every login and when the user navigates to the main home screen of your application.&#x20;
{% endhint %}

## Profile Schema&#x20;

The JSON snippet below shows the structure of a user profile.

```javascript
{
  "country": "BE",
  "region": "string",
  "address_line1": "string",
  "address_line2": "string",
  "city": "string",
  "postal_code": "string",
  "weight": 0,
  "length": 0,
  "birthday": {},
  "gender": 1,
  "comorbidities": [
    "HEART_FAILURE"
  ],
  "physician": "string",
  "smoker": true,
  "activity": "NOT_ACTIVE",
  "fibricheck_info": {
    "app": {
      "version": "string"
    },
    "device": {
      "os": "string",
      "model": "string",
      "type": "android",
      "manufacturer": "string"
    }
  },
  "impediments": [
    "TREMOR"
  ],
  "custom_fields": {
    "additionalProp1": "string",
    "additionalProp2": "string",
    "additionalProp3": "string"
  }
}
```

## Update Profile

### SDK

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

```dart
import 'package:flutter_fibricheck_sdk/flutter_fibricheck_sdk.dart';
import 'package:device_info_plus/device_info_plus.dart';

var deviceInfo = DeviceInfoPlugin();
    AndroidDeviceInfo androidInfo;
    IosDeviceInfo iosInfo;

    String? os;
    String? model;
    String? manufacturer;

    if (Platform.isAndroid) {
      androidInfo = await deviceInfo.androidInfo;
      os = androidInfo.version.release;
      model = androidInfo.model;
      manufacturer = androidInfo.manufacturer;
    } else if (Platform.isIOS) {
      iosInfo = await deviceInfo.iosInfo;
      os = iosInfo.systemVersion;
      model = iosInfo.localizedModel;
      manufacturer = 'Apple';
    }

await _sdk.updateProfile(
        ProfileData(
            addressLine1: "",
            addressLine2: "",
            weight: int,
            length: int,
            smoker: bool,
            activity: ProfileActivity...,
            fibricheckInfo: FibricheckInfo(
              app: App(version: "1.0.0"),
              device: Device(
                manufacturer: manufacturer,
                type: Platform.isAndroid ? DeviceType.android : DeviceType.ios,
                model: model,
                os: iosInfo.systemVersion,
              ),
            )));
```

{% endtab %}

{% tab title="React Native" %}

```typescript
import DeviceInfo from 'react-native-device-info';

const appVersion = DeviceInfo.getVersion();
const isAndroid = Platform.OS === 'android';

const deviceOSVersion = DeviceInfo.getSystemVersion();
const deviceModel = isAndroid
  ? DeviceInfo.getModel()
  : DeviceInfo.getDeviceId();
deviceSystemName = isAndroid ? 'android' : 'ios';
deviceManufacturer = await DeviceInfo.getManufacturer();

const profileData = {
  birthday: '06/07/1990';
  gender: Gender.Male;
  fibricheck_info:
   app: {
      version: appVersion,
    },
    device: {
      os: deviceOSVersion,
      model: deviceModel,
      type: deviceSystemName,
      manufacturer: deviceManufacturer,
    }
  }
};

await sdk.updateProfile(profileData);
```

{% endtab %}
{% endtabs %}

### REST API

If you want to update the profile using the REST API, you need to know the `userId` of the user that is currently logged in. The `userId` is available in response of the `/tokens` endpoint after a successful authentication attempt.

In the body of the API call you can provide all the profile fields, or a subset from the [profile schema](#profile-schema) in JSON format. If you provide a subset, the updated values will be merged into the existing profile.

## Update the profile of the authenticated user

<mark style="color:orange;">`PUT`</mark> `https://api.fibricheck.com/profiles/v1?id={userId}`

#### Query Parameters

| Name   | Type   | Description                                                    |
| ------ | ------ | -------------------------------------------------------------- |
| userId | String | The user for which you want to update the profile information. |

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

```json
{
    "records_affected": 1
}
```

{% endtab %}
{% endtabs %}

## Get information about the authenticated user

For some API functionality, you need to have more information about the authenticated user. For example, to generate a periodic report you'll want to know the language in which to generate the report.&#x20;

If you're using the SDK, the information will be fetched internally. If you are using the REST API endpoints, you can use the `/me` call to get the necessary information.

## Get information about the authenticated user

<mark style="color:blue;">`GET`</mark> `https://api.fibricheck.com/users/v1/me`

{% tabs %}
{% tab title="200: OK Authenticated User Information" %}

```javascript
{
    "id": "5811c7a046e0fb000530a465",
    "first_name": "John",
    "last_name": "Doe",
    "language": "EN",
    "time_zone": "Europe/Brussels",
    "email": "testing2@fibricheck.com",
    "phone_number": "1337606",
    "activation": true,
    "patient_enlistments": [
        {
            "group_id": "5cb9706059080100098d34ab",
            "expiry_timestamp": 1652622905035,
            "expired": true,
            "creation_timestamp": 1556286905035
        },
        {
            "group_id": "6258156365220500073f0c7d",
            "expiry_timestamp": 1677767836482,
            "expired": false,
            "creation_timestamp": 1676558236482
        }
    ],
    "staff_enlistments": [
        {
            "roles": [],
            "creation_timestamp": 1629206655891,
            "update_timestamp": 1677079784835,
            "group_id": "5919759152faff000545b18c"
        }
    ],
    "last_failed_timestamp": 1676983781866,
    "failed_count": 0,
    "creation_timestamp": 1477560224809,
    "update_timestamp": 1677079784835,
    "profile_image": "98fde5bc6faae6d4f92d89d24f1fcf941cd10633"
}
```

{% endtab %}
{% endtabs %}
