# Legal Documents

## getLegalDocuments

Fetches a collection of currently active legal documents.

#### Parameters:

* `userProfileId`: The ID is available in activation or user call

### Concrete Example

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

```swift
let service = LegalDocumentsService()
service.getLegalDocuments(
    userProfileId: userProfileId,
    then: { result in
        switch result {
        case: .success(_)
            // successfully retrieved
        case: .failure(_)
            // failure error
        }
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LegalDocumentsService()
service.getLegalDocuments(userProfileId) { result: Result<List<LegalDocumentsCollection>> ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
    }
})
```

{% endtab %}
{% endtabs %}

## getLegalDocumentContent

Fetches the full content for a specific legal document.

#### Parameters:

* `documentId`: The document ID that is available in the previous call. (when the list of documents is fetched)
* `userProfileId`: The ID is available in activation or user call
* `languageTag` : Optional language tag (e.g., "en", "fr-CA"). If null or blank, the backend default localization is applied.

To get the specific legal document, first host app needs to retrieve the `documentId` provided when the `getLegalDocuments` API call is made and need to provide the retrieved `documentId` as an argument to `submitConsent` API

### Concrete Example

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

```swift
let service = LegalDocumentsService()
service.getLegalDocumentContent(
    userProfileId: String,
    documentId: String,
    languageTag: String?
    ) { result in
        switch result {
        case: .success(_)
            // successfully updated
        case: .failure(_)
            // failure error
        }
    }
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LegalDocumentsService()
service.getLegalDocumentContent(
    userProfileId,
    documentId,
    languageTag,
    ) { result: Result<LegalDocumentContent> ->
        if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
            val content = result.value
        }
    }
```

{% endtab %}
{% endtabs %}

## submitConsent

Submits user consent for a specific legal document.

#### Parameters:

* `documentId`: The document ID that is available in the previous call. (when the list of documents is fetched)
* `userProfileId`: The ID is available in activation or user call

To submit the user consent, first host app needs to retrieve the `documentId` provided when the `getLegalDocuments` API call is made and need to provide the retrieved `documentId` as an argument to `submitConsent` API

### Concrete Example

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

<pre class="language-swift"><code class="lang-swift">let service = LegalDocumentsService()
<strong>service.submitConsent(for userProfileId: String, documentId: String) { result in
</strong>        switch result {
        case: .success(_)
            // successfully updated
        case: .failure(_)
            // failure error
        }
    })
</code></pre>

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val service = LegalDocumentsService()
service.submitConsent(
    userProfileId,
    documentId
    ) { result: Result<LegalDocumentsAccept> ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val content = result.value
    }
}
```

{% endtab %}
{% endtabs %}


---

# 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/legal-documents.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.
