Hi,
I'm trying to add a ports list to an alias by API
def add_client_dstport_alias(cn, cn_ports):
payload = {
"alias": {
"type": "port",
"enabled": "1",
"name": cn + '_port',
"description": cn,
"content": "8,18",
"proto": "",
"updatefreq": "",
"counters": "0",
"categories": ""
}
}
return api_post('/api/firewall/alias/addItem', payload)
and I got en error:
Entry "8,18" is not a valid port number
I tried different ways to add ports, such like a port range: 8-18, and I got same error. But if I add just one port by API, it works. If I add the other ports on GUI by hand, evreything goes well.
Please help me
regards
Compare it in the web developer tools
https://docs.opnsense.org/development/how-tos/api.html#using-browser-console-to-inspect-api
From what that shows, the listed ports are transmitted one per line, separated by a newline character, not by a comma. A range would probably be given by 1:18, not 1-18.
Quote from: meyergru on July 17, 2025, 06:43:30 PMFrom what that shows, the listed ports are transmitted one per line, separated by a newline character, not by a comma. A range would probably be given by 1:18, not 1-18.
Yeah, you right. a port range is more like 1:18. but I don't understand what you mean by " separated by a newline character". "content": "8,18" is not supposed to put 8,18 in content ?
When you try to enter that in the web UI, you will get an error, too. When you expand the text in the content box, you see that a correct list will be showing every port on its own line. In the JSON, you need to have a string like "8\n18".
Quote from: meyergru on Today at 09:43:35 AMWhen you try to enter that in the web UI, you will get an error, too. When you expand the text in the content box, you see that a correct list will be showing every port on its own line. In the JSON, you need to have a string like "8\n18".
That works well. Thanks for helps.