# Api post request 404

**URL:** <https://forum.pritunl.com/t/api-post-request-404/2013>\
**Category:** Pritunl VPN\
**Tags:** pritunl\
**Created:** [April 25, 2024, 4:38pm UTC](https://forum.pritunl.com/t/api-post-request-404/2013 "2024-04-25T16:38:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubavb](https://forum.pritunl.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lubavb](https://forum.pritunl.com/u/lubavb)\
**Post date:** [April 25, 2024, 4:38pm UTC](https://forum.pritunl.com/t/api-post-request-404/2013/1 "2024-04-25T16:38:28Z")

</div>

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]

```auto
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](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’

```auto

```

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [April 25, 2024, 8:06pm UTC](https://forum.pritunl.com/t/api-post-request-404/2013/2 "2024-04-25T20:06:59Z")

</div>

There is an example usage of this API in [**pritunl/tools  
/add\_aws\_ranges.py**](https://github.com/pritunl/pritunl/blob/master/tools/add_aws_ranges.py). Use Chrome Developer Tools to find the usage of other API endpoints.

---

<div class="post-metadata">

**Author:** ![lubavb](https://forum.pritunl.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lubavb](https://forum.pritunl.com/u/lubavb)\
**Post date:** [February 7, 2025, 11:23am UTC](https://forum.pritunl.com/t/api-post-request-404/2013/3 "2025-02-07T11:23:12Z")

</div>

Maybe someone else will need it. I wrote an automation script for adding and removing routes on the Pritunl server, as there is no proper documentation for the API. Feel free to use it.  
[pritunl\_api\_scripts](https://github.com/lubovfn/pritunl_api_scripts/tree/main)
