# Named Driver

## Fetch

To fetch the Named Drivers details, the following API can be used.

### Concrete Example

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

```swift
let service = NamedDriverService()
service.fetch(then: { result in
    switch result {
    case: .success(_)
        // successfully retrieved
    case: .failure(_)
        // failure error
    }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = NamedDriver()
service.fetch() { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
    }
})
```

{% endtab %}
{% endtabs %}

## Update

Updates the named driver's email and phone number and returns the updated named driver object

#### Parameters:

* `userId`: User id of a named driver retrieved from `fetch` api
* `email`: Email to be updated
* `phone`: Phone number to be updated

To update the named driver's details, first host app needs to retrieve the user Id provided when the `fetch` API call is made and need to provide the retrieved user id as an argument to `updateNamedDriver` API

### Concrete Example

To update the Named Drivers details, the following API can be used.

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

```swift
let service = NamedDriverService()
service.updateNamedDriver(userId: Int,
                          email: String,
                          phone: String,
                          then: { result in
    switch result {
    case: .success(_)
        // successfully updated
    case: .failure(_)
        // failure error
    }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = NamedDriver()
service.updateNamedDriver(userId: Int,
                          email: String,
                          phone: String,) 
                          { result: Result<Content?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
        completionHandler(content)
    }
})
```

{% endtab %}
{% endtabs %}

### Error codes

* fetch
  * 404 -> No Named Drivers Found
* updateNamedDriver
  * 409 -> Conflict email exists for another user
  * 404 -> Failed to locate named driver for primary policy holder


---

# 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://sdk.ims.tech/drivesync-portal/named-driver.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.
