# API IP Diversion

APIs registered in the system can be configured to allocate IP traffic and restrict access.

This application is similar to the concept of double centers. Using the concept of branch company for explanation, Taipei IPs need to use Taipei APIs, and Kaohsiung IPs need to use Kaohsiung APIs; setting it properly will make them easier to manage and prevent errors from being accidentally triggered.

### Registering APIs <a href="#toc164347060" id="toc164347060"></a>

1. Go to **API Management** > **API Registry**, and click **CUSTOMIZE** to enter the registration page.
2. Fill in the required fields: **API Name, digiRunner Proxy Path** and **Http Methods**.
3. Since authentication is not required for now, select **No Auth**.

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/dxm0280sQFWhK4t554iJ/0.png)

4. After selecting **Source IP diversion** for the **Target URL** field, click on the **+** icon to get two Source IP input boxes.

* Fill in the local IP for the first Source IP, and fill in the API address to call for the target URL.
* Fill in the Custom IP for the first Source IP, and fill in the API address to call for the target URL.

5. Click **Register** to complete the API registration.

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/ApRRq4FIZJiwvkOj2dWb/1.png)

### Calling API Verification Dispatch Function

1. Go to **API Management** > **API List**, and select the API, the status light is red ![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/vCngrdjXM9A1xqvNzAUA/2.png) by default; click **Enable**.

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/bwWFADkAqnTPdesgrRHb/3.png)

2. A confirmation window will pop up, click **Confirm** to finish enabling the API, and the status light will turn green ![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/UtTQ3QaN5kDYL50isLft/4.png).

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/vFnV1eKpD8UmVxQhsf34/5.png)

3. Click on the **Test** icon ![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/DeqMuodRORu5ILsjIy4X/6.png) to open the testing area.
4. Select **No Auth** for **Authorization**.
5. Click **Test** to view the response. Since the local IP is defined in the Source IP, it is expected that the return code will be received successfully and be *200*, and the **Body** contains the data defined by the API.

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/Batzpx0Sf4q686ri4By4/7.png)

6. In the **Key** field of the **Request Header**, fill in *X-Forwarded-For*, and in the **Value** field, fill in the custom IP that matches the Source IP.
7. Click **Test** to view the response. Since the custom IP is defined in the Source IP, it is expected that the return code will be received successfully and be *200*, and the **Body** contains the data defined by the API.

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/ChpaDtZoevSmGymjg8pu/8.png)

8. In the **Key** field of the **Request Header**, fill in *X-Forwarded-For*, and in the **Value** field, fill in a random custom IP.
9. Click **Test** to view the response. Since the IP is not defined in the Source IP, it is expected that the call will fail, the return code received will be *401*, and the **Body** will respond "*`Missing srcUrl information`*".

![](https://content.gitbook.com/content/0choIC1BbdPOkKWOYGgk/blobs/8EILy5lO0yS1WxxttWvo/9.png)


---

# 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://docs.tpi.dev/most-common-use-cases/api-ip-diversion.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.
