adding extra info in API posts.

NeilB
Getting noticed

adding extra info in API posts.

Hi,

 

I'm looking to add some new VLANs using the API and the main aspects work fine, however some variables appear to not be working successfully.

 

# ------------------------VARIABLES-----------------------------
# (1) Insert desired Network ID here from list above.
$networkid = $Test_Site
# (2) Insert New Management Subnet
$MGNTRANGE = "10.1.2.0/24"
# (3) Insert New DATA Subnet
$DATARANGE = "10.2.2.0/24"
# (4) Insert New VOICE Subnet
$VOIPRANGE = "10.3.2.0/24"

# -------------------------------------------------------------

 

 

#----Formatting-----
$MGNTRANGESPLIT = $MGNTRANGE.split('.')
$MGNTRANGEIP = "$($MGNTRANGESPLIT[0]).$($MGNTRANGESPLIT[1]).$($MGNTRANGESPLIT[2]).1"

$DATARANGESPLIT = $DATARANGE.split('.')
$DATARANGEIP = "$($DATARANGESPLIT[0]).$($DATARANGESPLIT[1]).$($DATARANGESPLIT[2])"

$VOIPRANGESPLIT = $VOIPRANGE.split('.')
$VOIPRANGEIP = "$($VOIPRANGESPLIT[0]).$($VOIPRANGESPLIT[1]).$($VOIPRANGESPLIT[2])"


#Array of rules required to be pushed to network as defined above. All fields are required.
$data = @{
            id="3000"
            networkId="$networkid"
            name="BLEUGH"
            applianceIp="$DATARANGEIP.1"
            subnet="$DATARANGE"
            dnsNameservers="upstream_dns"
            dhcpHandling="Run a DHCP server"
            dhcpLeaseTime="1 hour"
            dhcpOptions= 
                @(
                    @{
                        "code"=43
                        "type"=text
                        "value"="<DHCP OPTION INFORMATION>"
                    }
                )
        }
            

#Convert arrays above to JSON format.
$json = $data | ConvertTo-Json -Depth 4;
Write-Host $json
 
 
This is written in powershell as i am using the Invoke-RestMethod call to Post this data, however the additional hashtable for dhcpOptions heading doesn't show in the dashboard, but shows correctly in the JSON output that is sent (See below). Also the dhcpLeaseTime value doesn't appear to change either if i enter "1 week" or "1 hour", it just appears to default to "1 day".
 
{
"subnet": "10.2.2.0/24",
"dnsNameservers": "upstream_dns",
"name": "BLEUGH",
"dhcpHandling": "Run a DHCP server",
"applianceIp": "10.2.2.1",
"id": "3000",
"dhcpLeaseTime": "1 hour",
"networkId": "<NETWORK ID>",
"dhcpOptions": [
{
"value": "<DHCP OPTION INFORMATION>",
"code": "43",
"type": "text"
}
]
}
 
 
 
 
Any help gratefully appreciated,
 
Cheers
Neil
2 REPLIES 2
Edgar-VO
Building a reputation

Hey,

 

This is something in Python

 

my_lijst = []
my_lijst.append(eval("{'type': 'text', 'code': '15', 'value': 'company.com'}"))
param['dhcpOptions'] = my_lijst

 

 

response = dashboard.vlans.updateNetworkVlan(network_id,def_vlan_id,**param)
 
------------------------------------
 

this is cause dhcpOptions should be an array..

 

Usually i do create a VLAN/Site what i want with the GUI, then i export the JSON using the API....That information i will use as as a template

 


@Edgar-VO wrote:

Hey,

 

This is something in Python

 

my_lijst = []
my_lijst.append(eval("{'type': 'text', 'code': '15', 'value': 'company.com'}"))
param['dhcpOptions'] = my_lijst

 

 

response = dashboard.vlans.updateNetworkVlan(network_id,def_vlan_id,**param)
 
------------------------------------
 

this is cause dhcpOptions should be an array.. five nights at freddy's

 

Usually i do create a VLAN/Site what i want with the GUI, then i export the JSON using the API....That information i will use as as a template

 


Thanks, I give it a go to figure it out.

Get notified when there are additional replies to this discussion.