> ## Documentation Index
> Fetch the complete documentation index at: https://developer.sandbox.co.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch Documents using DigiLocker

> This recipe provides a step-by-step process to integrate DigiLocker APIs into your application.

## 1. Initiate Session

To begin the DigiLocker workflow, your application must first initiate a **session**
using the [**Initiate Session**](https://developer.sandbox.co.in/api-reference/kyc/digilocker/endpoints/initiate_session.md) endpoint.

This endpoint initializes the consent process and returns essential details for user authorization.

> **cURL Request**
>
> ```bash theme={null}
>     curl --request POST \
>       --url https://api.sandbox.co.in/kyc/digilocker/sessions/init \
>       --header 'Authorization: <authorization>' \
>       --header 'Content-Type: application/json' \
>       --header 'x-api-key: <x-api-key>' \
>       --data '{
>       "@entity": "in.co.sandbox.kyc.digilocker.session.request",
>       "flow": "signin",
>       "doc_types": [
>         "aadhaar",
>         "pan"
>       ],
>       "redirect_url": "https://sandbox.co.in"
>     }'
> ```

When the session is created successfully, you’ll receive:

**session\_id** `string` *required*

A unique identifier used to track and fetch status for this specific DigiLocker consent session.

**authorization\_url** `string` *required*

The URL where the user should be redirected to grant consent for sharing their DigiLocker documents.

## 2. Redirect the User to DigiLocker

Once the session is initiated, redirect the user to the **authorization\_url**.

At DigiLocker, the user will:

* Authenticate using their DigiLocker account
* Review permissions
* Grant consent for your application to access their documents

This authorization step is **mandatory** before any document can be fetched.

## 3. Handle Session Success and Failure

You can determine whether the user consented by periodically call the \
[**Session Status API**](https://developer.sandbox.co.in/api-reference/kyc/digilocker/endpoints/session_status.md) using the `session_id`.

> **cURL Request**
>
> ```bash theme={null}
>     curl --request GET \
>       --url https://api.sandbox.co.in/kyc/digilocker/sessions/{session_id}/status \
>       --header 'Authorization: <authorization>' \
>       --header 'x-api-key: <x-api-key>'
> ```

## 4. Fetch Documents

Once the session status is **succeeded**, you may proceed to retrieve the user's DigiLocker documents using the [Fetch Document API](https://developer.sandbox.co.in/api-reference/kyc/digilocker/endpoints/fetch_document.md).

> **cURL Request**
>
> ```bash theme={null}
> curl --request GET \
> --url https://api.sandbox.co.in/kyc/digilocker/sessions/{session_id}/documents/{doc_type} \
> --header 'Authorization: <authorization>' \
> --header 'x-api-key: <x-api-key>'
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.