API request to add a new NETWORK object

Before posting something, READ the changelog, WATCH the videos, howto and provide following:
Your install is: Bare metal, ESXi, what CPU model, RAM, HD, what EVE version you have, output of the uname -a and any other info that might help us faster.

Moderator: mike

Post Reply
funtick
Posts: 1
Joined: Tue Aug 08, 2017 9:48 am

API request to add a new NETWORK object

Post by funtick » Fri Jul 22, 2022 10:47 am

Hi commuity,

I'm using EVE-NG release 2.0.3-112 and trying to add a new network to lab via API:

Code: Select all

import requests
url = "http://172.18.70.84/api/labs/user_name/104/eve.unl/networks"
payload={"count":"1","visibility":"1","name":"Net","type":"bridge","postfix":0}
headers = {
  'Cookie': 'unetlab_session=bce95412-ad99-4d7f-b12a-7394b4b2ff51'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
But getting following error message:

Code: Select all

{"code":400,"status":"fail","message":"Cannot add network to the lab (20021)."}
Can someone advice me what is wrong with request and is it even possible to add a new network via API?

p.s. same code is work to create regular router object.

Lychos1985
Posts: 6
Joined: Thu Dec 03, 2020 4:50 pm

Re: API request to add a new NETWORK object

Post by Lychos1985 » Mon Feb 17, 2025 2:59 pm

Perhaps, you cookie will be new conection.

First login and, get the new cookies!:

def login(self):
payload = {
"username": self.username,
"password": self.password
}
loginRequest = requests.post(
f'{self.url_base}auth/login',
json=payload
)
self.cookie = loginRequest.cookies.get_dict()

then, create a network:

payloadNewConnection = {
"count":1,
"name": connectionName,
"type":"bridge",
"left":693,
"top":274,
"visibility":1,
"postfix":0
}
addLinkRequest = requests.post(
f'{self.url_base}labs/{self.labName}.unl/networks',
headers=self.headers,
json=payloadNewConnection,
cookies=self.cookie
)

Best Regards

Post Reply