> For the complete documentation index, see [llms.txt](https://developer.sahamati.org.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.sahamati.org.in/sahamatinet-poc/integration-steps/integration-with-router/sample-code-snippets/python.md).

# Python

***

<details>

<summary>Without Router - Current Approach</summary>

```python
# Assuming this as previous logic without Router
import requests

entity_metadata_from_cr = {
    "baseUrl": "http://fip-1.dev.sahamati.org.in/fip-simulate",
    "id": "FIP-SIMULATOR"
}

def get_http_config(base_url, route, headers, data, method_type):
    return {
        "url": f"{base_url}{route}",
        "headers": headers,
        "data": data,
        "method": method_type
    }

def execute_discovery_request():
    route = "/v2/Accounts/discover"
    
    config = get_http_config(
        base_url=entity_metadata_from_cr["baseUrl"],
        route=route,
        headers={},
        data={},
        method_type="POST"
    )
    
    try:
        response = requests.request(**config)
        return response.json()
    except Exception as error:
        print(f"Error making discovery request: {str(error)}")
        raise
def perform_another_operations(account_discover_response):
    print("Perform another operations with the response", account_discover_response)

if __name__ == "__main__":
    try:
        response = execute_discovery_request()
        perform_another_operations(response)
        print("Account discovery successful.")
    except Exception:
        print("Account discovery failed.")
    finally:
        print("Account discovery completed.")

```

</details>

<details>

<summary>With Router Integration</summary>

```python
# Changes to implementation to integrate with Router

import requests
import json
import base64

# Start - New Changes 

def generate_base64_encoded_json(json_data):
    json_str = json.dumps(json_data)
    return base64.b64encode(json_str.encode()).decode()

def generate_request_meta(recipient_id):
    context = {"recipient-id": recipient_id}
    return generate_base64_encoded_json(context)

def add_sahamati_configuration(config, route):
    router_url = "http://api.dev.sahamati.org.in/router"
    config["url"] = f"{router_url}{route}"
    if "headers" not in config:
        config["headers"] = {}
    config["headers"]["x-request-meta"] = generate_request_meta(entity_metadata_from_cr["id"])
    return config

# END - New Changes

# OLD Changes
entity_metadata_from_cr = {
    "baseUrl": "http://fip-1.dev.sahamati.org.in/fip-simulate",
    "id": "FIP-SIMULATOR"
}

def get_http_config(base_url, route, headers, data, method_type):
    return {
        "url": f"{base_url}{route}",
        "headers": headers,
        "data": data,
        "method": method_type
    }

def execute_discovery_request():
    route = "/v2/Accounts/discover"
    
    config = get_http_config(
        base_url=entity_metadata_from_cr["baseUrl"],
        route=route,
        headers={},
        data={},
        method_type="POST"
    )

    # add Sahamati configuration [Start]
    config = add_sahamati_configuration(config, route)
    # add Sahamati configuration [End]

    try:
        response = requests.request(**config)
        return response.json()
    except Exception as error:
        print(f"Error making discovery request: {str(error)}")
        raise

def perform_another_operations(account_discover_response):
    print("Perform another operations with the response", account_discover_response)

try:
    response = execute_discovery_request()
    perform_another_operations(response)
    print("Account discovery successful.")
except Exception as e:
    print(e)
    print("Account discovery failed.")
finally:
    print("Account discovery completed.")
```

</details>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.sahamati.org.in/sahamatinet-poc/integration-steps/integration-with-router/sample-code-snippets/python.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
