Updating routes using API is not removing old routes

The way our networking is set up, we need one of our servers to route data to some ips that might change from time to time. Therefore we have set up a job that runs from time to time, checking the servers current routes, and what the ip for the target is. If they are different, then we update them using the api based on this example: pritunl/tools/add_aws_ranges.py at master · pritunl/pritunl · GitHub

Checking our logs, we get an output saying what routes that are being added:

    "network": "<ip-1>/32",
    "comment": "Route updated <timestamp>",
    "nat": true
}, {
    "network": "<ip-2>/32",
    "comment": "Route updated <timestamp>",
    "nat": true

That is the data being used in the auth_request function:

    response = auth_request(
        "/server/%s/routes" % SERVER_ID,
        headers={"Content-Type": "application/json"},

However, when checking the routes after this function is executed, the server contains more routes than the ones in the POST request. How can I solve this issue without having to manually remove an old route from time to time?

The API will either add or remove routes. It can’t update all the routes and overwrite the existing route set. You will need to remove the other routes.