How to add new dhcp relay server from postman API

Ozzyraven
Just browsing

How to add new dhcp relay server from postman API

I need to add an additional DHCP server to several sites as a backup but the postman API call wipes the current values and just add the new ones. 

 

for example, I currently have different server IPs  per region and I want to add a central DHCP relay as 192.168.17.25 but when I run the API it just wipes the current values and  adds just the IP.

 

$body = @"
{
`"dhcpHandling`": `"Relay DHCP to another server`",
`"dhcpRelayServerIps`": [
`"192.168.17.25`",
]
}
"@

 

$response = Invoke-RestMethod $endpointuplink -Method 'PUT' -Headers $headers -Body $body
$response | ConvertTo-Json

 

Anyone with a similar situation that can share any knowledge?

2 Replies 2
Ryan_Miles
Meraki Employee
Meraki Employee

Send both the existing and the new IP. Example of updating my VLAN with a 3rd server IP while retaining the existing first two IPs.
 
{
"dhcpRelayServerIps": [
"172.31.31.123",
"172.31.31.124",
"172.31.31.125"
]
}
Ryan

If you found this post helpful, please give it Kudos. If my answer solves your problem please click Accept as Solution so others can benefit from it.
Ozzyraven
Just browsing

Hi, the issue is that we have several different DHCP servers for several different sites so that would not work.

Fortunatelly I was able to figure this out getting the network vlan data 1st and then putting it in a variable and then concatenate the new IP. this is a snip of code, my logic can be a little weird, im just starting with this :).

 

#This gets the current Network Vlan values
$request = Invoke-RestMethod $endpointuplink -Method 'GET' -Headers $headers

#This code will add the "" to the DHCP IP values and format it for the API call to work correctly
[string]$servers = $null
[Array]$servers = $request.dhcpRelayServerIps
[Array]$current = '"{0}"' -f ($servers -join '","')

if ($servers -contains $newserver){
write-host("DHCP IP is duplicated")
}else {

$body = @"
{
`"dhcpRelayServerIps`": [$current,"$newserver"]
}
"@


$response = Invoke-RestMethod $endpointuplink -Method 'PUT' -Headers $headers -Body $body
$response | ConvertTo-Json

Get notified when there are additional replies to this discussion.