Api post request 404

Hi.
My organization uses the Enterprise Plan.
I’m having a problem adding routes to the server, I’m getting a 404 or 400 error.

I can connect via API and get the server status, perform a get request, but nothing else.
all my attempts to add routes or remove failed 404.
Here is a script that should add routes:
pip install pritunl-api[cli]

import yaml
import requests
import hmac
import hashlib
import base64
import time
import uuid
import json
import ipaddress

def load_settings(filename='pritunl_settings.yml'):
    with open(filename, 'r') as file:
        return yaml.safe_load(file)


def create_signature(api_token, api_secret, method, path):
    timestamp = str(int(time.time()))
    nonce = uuid.uuid4().hex
    auth_string = '&'.join([api_token, timestamp, nonce, method.upper(), path])
    signature = hmac.new(api_secret.encode(), auth_string.encode(), hashlib.sha256).digest()
    return {
        'Auth-Token': api_token,
        'Auth-Timestamp': timestamp,
        'Auth-Nonce': nonce,
        'Auth-Signature': base64.b64encode(signature).decode()
    }


def send_request(url, method, headers, data=None, cert_path=('/etc/ssl/mycert.crt', '/etc/ssl/mycert.key')):
    if data:
        response = requests.request(method, url, headers=headers, json=data, cert=cert_path, verify=True)
    else:
        response = requests.request(method, url, headers=headers, cert=cert_path, verify=True)
    return response


def manage_server(base_url, api_token, api_secret, server_id, routes):
    # stop server
    stop_path = f'/server/{server_id}/stop'
    stop_url = f'{base_url}{stop_path}'
    stop_headers = create_signature(api_token, api_secret, 'POST', stop_path)
    stop_response = send_request(stop_url, 'POST', stop_headers)
    print(f'Server stop response: {stop_response.status_code}')

    # Add route
    for route in routes:
        route_path = f'/server/{server_id}/route'
        route_url = f'{base_url}{route_path}'
        route_headers = create_signature(api_token, api_secret, 'POST', route_path)
        route_data = {'network': route}
        route_response = send_request(route_url, 'POST', route_headers, route_data)
        print(f'Add route response ({route}): {route_response.status_code}')

    # Run server
    start_path = f'/server/{server_id}/start'
    start_url = f'{base_url}{start_path}'
    start_headers = create_signature(api_token, api_secret, 'POST', start_path)
    start_response = send_request(start_url, 'POST', start_headers)
    print(f'Server start response: {start_response.status_code}')


def main():
    settings = load_settings()
    base_url = settings['base_url']
    api_token = settings['api_token']
    api_secret = settings['api_secret']

    # yaml add configure
    first_server = settings['servers'][0]
    server_id = first_server['id']  
    routes = settings['routes'][0]['network']  # add firt route 

    manage_server(base_url, api_token, api_secret, server_id, routes)

if __name__ == '__main__':
    main()

config.yaml
base_url: ‘https://vpn.com
api_token: ‘"
api_secret: '

servers:

  • id: ‘6628ff14a6d662c72caacbba’
    name: ‘vpn-test’
    port: 10696
    network: ‘10.80.50.0/24’
    nat: False
    net_gateway: False
    dns_servers:
    • ‘8.8.8.8’

routes:

  • server: ‘6628ff14a6d662c72caacbba’
    network:
    • ‘10.75.0.0/24’
    • ‘10.69.69.0/24’
    • ‘10.69.0.0/24’

There is an example usage of this API in pritunl/tools
/add_aws_ranges.py
. Use Chrome Developer Tools to find the usage of other API endpoints.