Page 1 of 1

API request to add a new NETWORK object

Posted: Fri Jul 22, 2022 10:47 am
by funtick
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.

Re: API request to add a new NETWORK object

Posted: Mon Feb 17, 2025 2:59 pm
by Lychos1985
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