> For the complete documentation index, see [llms.txt](https://docs.digit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digit.org/platform/guides/developer-guide/backend-developer-guide/section-3-integrate-microservices/integrate-idgen-service.md).

# Integrate IDGen Service

Describes how to integrate with DIGIT's ID Gen service

## Overview

This page provides the steps to integrate with the IDGen Service. Each application needs to have a unique ID. The [IDGen service](/platform/platform/core-services/id-generation-service.md) generates these unique IDs. ID format can be customised via configuration in MDMS.

## Steps

1. Add the ID format that needs to be generated in this file - [Id Format Mdms File](https://github.com/egovernments/egov-mdms-data/blob/DEV/data/pb/common-masters/IdFormat.json). The following config has been added for this module:

```
{
"format": "PB-BTR-[cy:yyyy-MM-dd]-[SEQ_EG_BTR_ID]",
"idname": "btr.registrationid"
}
```

2. Restart the IDGen service and MDMS service and port-forward IDGen service to port 8285:

```
kubectl port-forward <IDGEN_SERVICE_POD_NAME> 8285:8080
```

{% hint style="info" %}
Note that you can set the ID format in the application.properties file of IDGen service and run the service locally if you don't have access to a DIGIT environment.
{% endhint %}

3. Hit the below curl to verify that the format is added properly. The "ID" name needs to match exactly with what was added in MDMS.

{% code lineNumbers="true" %}

```bash
curl --location --request POST 'http://localhost:8285/egov-idgen/id/_generate' \
--header 'Content-Type: application/json' \
--data-raw '{
    "RequestInfo": {
        "apiId": "string",
        "ver": "string",
        "ts": null,
        "action": "string",
        "did": "string",
        "key": "string",
        "msgId": "string",
        "authToken": "6456b2cf-49ca-47c7-b7b6-c179f19614c7",
        "correlationId": "e721639b-c095-40b3-86e2-acecb2cb6efb",
        "userInfo": {
            "id": 23299,
            "uuid": "e721639b-c095-40b3-86e2-acecb2cb6efb",
            "userName": "9337682030",
            "name": "Abhilash Seth",
            "type": "EMPLOYEE",
            "mobileNumber": "9337682030",
            "emailId": "abhilash.seth@gmail.com",
            "roles": [
                {
                    "id": 281,
                    "name": "Employee"
                }
            ]
        }
    },
    "idRequests": [
        {
            "tenantId": "pb.amritsar",
            "idName": "btr.registrationid"
        }
    ]
}'
```

{% endcode %}

4. Once verified, we can call the ID generation service from within our application and generate the registrationId. \\
5. In the BirthApplicationEnrichment class, update the enrichBirthApplication method as shown below:

```java
  public void enrichBirthApplication(BirthRegistrationRequest birthRegistrationRequest) {
        List<String> birthRegistrationIdList = idgenUtil.getIdList(birthRegistrationRequest.getRequestInfo(), birthRegistrationRequest.getBirthRegistrationApplications().get(0).getTenantId(), "btr.registrationid", "", birthRegistrationRequest.getBirthRegistrationApplications().size());
        Integer index = 0;
        for(BirthRegistrationApplication application : birthRegistrationRequest.getBirthRegistrationApplications()){
            // Enrich audit details
            AuditDetails auditDetails = AuditDetails.builder().createdBy(birthRegistrationRequest.getRequestInfo().getUserInfo().getUuid()).createdTime(System.currentTimeMillis()).lastModifiedBy(birthRegistrationRequest.getRequestInfo().getUserInfo().getUuid()).lastModifiedTime(System.currentTimeMillis()).build();
            application.setAuditDetails(auditDetails);

            // Enrich UUID
            application.setId(UUID.randomUUID().toString());

//            Enrich application number from IDgen
            application.setApplicationNumber(birthRegistrationIdList.get(index++));
//             Enrich registration Id
            application.getAddress().setApplicationNumber(application.getId());

            // Enrich address UUID
            application.getAddress().setId(UUID.randomUUID().toString());

        }
    }
```

6. Make sure below ID generation host configuration is present in the application.properties file. Make sure to fill in the correct values for the host.

{% code lineNumbers="true" %}

```properties
#Idgen Config
egov.idgen.host=http://localhost:8285/ #REPLACE
egov.idgen.path=egov-idgen/id/_generate
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.digit.org/platform/guides/developer-guide/backend-developer-guide/section-3-integrate-microservices/integrate-idgen-service.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
