# Deep Linking

## What is Deep Linking?

Deep Linking is a technique in which a given URL or resource is used to open a specific page or screen on mobile. So, instead of just launching the app on mobile, using our deep link method can lead a user to open PAVE's PWA in their browser. When finished, they will be redirected to a specific page within your native app, providing a seamless mobile experience. This particular page or screen you provide as a redirect URL may reside under a series of hierarchical pages, hence the term "deep" in deep linking.

## How does the PAVE Deep Linking work?

<figure><img src="https://3056819394-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIMmt4CHr5aRB2VBMvpEQ%2Fuploads%2FvLVAuH9UiWwWd8xSGBw1%2F1.png?alt=media&#x26;token=33da23fa-8cf0-4ee7-987f-9d67041aa420" alt=""><figcaption><p>Flowchart diagram of PAVE Deep Linking</p></figcaption></figure>

## Create Session

Create a new session for every User by generating a session\_key.

## Create New Session

<mark style="color:green;">`POST`</mark> `https://openapi.paveapi.com/v1/sessions`

#### Headers

| Name                                            | Type   | Description                                 |
| ----------------------------------------------- | ------ | ------------------------------------------- |
| Accept<mark style="color:red;">\*</mark>        | String | application/json                            |
| Content-type<mark style="color:red;">\*</mark>  | String | application/json                            |
| API-Key<mark style="color:red;">\*</mark>       | String | Your API Key                                |
| API-Token<mark style="color:red;">\*</mark>     | String | Your Generated Access Token                 |
| API Timestamp<mark style="color:red;">\*</mark> | String | UTC Datetime, example: 2021-05-30T12:49:19Z |

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

```json
{
    "session_key": "XXX-ABCDE12345",
    "theme": "PRO",
    "active": true,
    "status": "IDLE",
    "redirect_url": "https://www.url-to-redirect-user-to.com",
    "inspect_started_at": null,
    "inspect_ended_at": null,
    "created_at": "2021-05-25T11:50:49.000000Z",
    "updated_at": "2021-05-25T11:50:49.000000Z",
    "language": "EN",
    "capture_url": "https://demoadmin.vehiclecapture.com/TCB-123...",
    "options": {
        "client_id": "SOUTH234889",
        "sms": {
            "to": "647-455-XXXX",
            "to_name": "Jane Smith",
            "from": "647-422-XXXX",
            "by": "Steve's Test Dealer",           
        }
    },
    "vehicle": {
        "vin": "JN1CV6AR9BMXXXXXX"
    }    
}
```

{% endtab %}

{% tab title="400: Bad Request Sample Reponse" %}

```json
{
    "message": "Required fields are missing or invalid.",
    "errors": {
        "session.redirect_url": [
            "Invalid redirect url"
        ],
        "sms.to": [
            "Invalid phone number"
        ],
        "vehicle.vin": [
            "VIN is too short, it must be 17 characters"
        ]
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Request

```json
{
    "vehicle": {
        "vin":"JN1CV6AR9BMXXXXXX",
        "year":"2011",
        "make":"Infiniti",
        "model":"G37",
        "body_type":"Sedan",
        "trim":"Luxury",
        "transmission":"Automatic",
        "ext_col":"Malbec Black",
        "int_col":"Wheat",
        "odom_reading":330477,
        "odom_unit":"KILOMETRES"
    },
    "session": {
        "theme": "LITE",
        "redirect_url": "https://www.url-to-redirect-user-to.com",
        "client_id": "SOUTH234889"
    },
    "sms": {
        "to": "647-455-XXXX",
        "to_name": "Jane Smith",
        "from": "647-422-XXXX",
        "by": "Steve Test Dealer"
    }
}
```

{% hint style="warning" %}
The **`redirect_url`** is the handoff URL that we will send your User to at the end of their PAVE session to continue their journey on your application or website. So if you want to use redirect link, you have to send it to us.
{% endhint %}

{% hint style="info" %}
Please, read the [Create Session document](https://docs.paveapi.com/integrations/developer-docs/sessions-1/post-create-new-session) for more information.
{% endhint %}

## Launch PAVE Capture UI

```
https://api.paveapi.com/v1/launch/:SESSION-ID
```

Once you have the Session Key generated it can be used to launch the capture UI, which begins the inspection process.

Replac&#x65;**: SESSION-ID** with the generated session-id belonging to the vehicle to be inspected.

Example:

```
https://api.paveapi.com/v1/launch/TMV-B0R97T5QOD/
```

Open links with Safari or chrome.

<figure><img src="https://3056819394-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIMmt4CHr5aRB2VBMvpEQ%2Fuploads%2FUeZt1WMkVeJ43fY7Kv90%2F2.png?alt=media&#x26;token=d4f9e6e4-2954-4dce-a3aa-5b6dc6f5c20b" alt=""><figcaption></figcaption></figure>

### Android

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

```
String url = "https://api.paveapi.com/v1/launch/TMV-B0R97T5QOD/";
try {
    Uri uri = Uri.parse("googlechrome://navigate?url=" + url);
    Intent i = new Intent(Intent.ACTION_VIEW, uri);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(i);
} catch (ActivityNotFoundException e) {
    // Chrome is probably not installed
}
```

{% endtab %}

{% tab title="Kotlin" %}

```
  val url = "https://capture-dev.paveapi.com/home/TMV-B0R97T5QOD/"
  try {
    val uri: Uri = Uri.parse("googlechrome://navigate?url=$url")
    val i = Intent(Intent.ACTION_VIEW, uri)
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        startActivity(i)
        } catch (e: ActivityNotFoundException) {
            // Chrome is probably not installed
        }
```

{% endtab %}
{% endtabs %}

### IOS

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

```
guard let url = URL(string: "https://api.paveapi.com/v1/launch/TMV-B0R97T5QOD/") 
else { return }
UIApplication.shared.open(url)
```

{% endtab %}

{% tab title="Objective C" %}

```
NSURL *url = [NSURL URLWithString:@"https://capture-dev.paveapi.com/home/TMV-B0R97T5QOD/"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
   [[UIApplication sharedApplication] openURL:url];
}
```

{% endtab %}
{% endtabs %}

### React Native

```
Linking.openURL('https://api.paveapi.com/v1/launch/TMV-B0R97T5QOD/')}}
```

## Result

After **PAVE Capture** successfully and tap on **`CLOSE`** button, you will redirect to your app.

<div align="center"><figure><img src="https://3056819394-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIMmt4CHr5aRB2VBMvpEQ%2Fuploads%2Fy325cYxprslHz1tAIWGT%2F3.gif?alt=media&#x26;token=29224046-1662-49cb-8978-475c0f1446b3" alt=""><figcaption></figcaption></figure></div>
