Reply

MAC Filter - add Extended Attribute Values

Techie
Posts: 11
10405     0

Can someone suggest what I am doing wrong when trying to add extended attribute values to a mac filter address?  Here's the URI that I'm using:

 

https://10.1.18.57/wapi/v2.3.1/macfilteraddress?_return_type=json-pretty&filter=Kelly_MAC&mac=11:22:... via REST&extattrs":{"Asset_Tag":{"value":"W27617"},"DataSource":{"value": "Manual"}

 

Here's the response I receive from Infoblox REST:

{ "Error": "AdmConProtoError: Invalid input: 'extattrs\":{\"Asset_Tag\":{\"value\":\"W27617\"},\"DataSource\":{\"value\": \"Manual\"}'", 
  "code": "Client.Ibap.Proto", 
  "text": "Invalid input: 'extattrs\":{\"Asset_Tag\":{\"value\":\"W27617\"},\"DataSource\":{\"value\": \"Manual\"}'"
}

 Thanks,

Art

Re: MAC Filter - add Extended Attribute Values

Adviser
Posts: 200
10406     0
Are you attempting to update the EAs via the URL or are you sending that data as part of a POST in the body? You cannot update values via the URL and you definitely need to use a POST method.

There’s a couple of small examples in the WAPI documentation to help you get started but I think you’ll find some code on Github that may be more helpful if you’re looking for specific examples.

Re: MAC Filter - add Extended Attribute Values

Techie
Posts: 11
10406     0

Yes, I was trying to use the URL.  It sounds like the base record must be added and then the EAs can be updated as a second transaction.  I'll work with that and see if I can get that to work.  Thanks.

Re: MAC Filter - add Extended Attribute Values

Community Manager
Community Manager
Posts: 248
10406     0

If you want to update or add a record you have to use the HTTP POST and PUT methods. You can't use an HTTP GET.

Re: MAC Filter - add Extended Attribute Values

[ Edited ]
Techie
Posts: 11
10406     0

Right - I have been trying that.  I keep getting a 400 error and don't know how to troubleshoot it,  When I can type a URL in the browser, I can figure it out, but since I can't do that for the Post method, I would like a suggestion on how to debug it..

 

Invoke-WebRequest -Uri $uri -ContentType application/json -Method Post -WebSession $ib_session -Body ([System.Text.Encoding]::UTF8.GetBytes($json))

 

$uri: 

https://10.1.18.57/wapi/v2.3.1/macfilteraddress/ZG5zLmNsdXN0ZXJfbWFjX2ZpbHRlcnNldF9pdGVtJEtlbGx5X01B...

 

I think it is because I don't know how to format the $json varialble because the extended attribute has nested values:

 

$json = '{  "extattrs":{"Asset_Tag":{"value":"W27617"},"DataSource":{"value": "Manual"},"DateAdded":{"value": "2016-09-28T11:01:00Z"},"Host_ID": {"value": "W6FYYH72"}}}'

 

 

Re: MAC Filter - add Extended Attribute Values

Member
Posts: 2
10406     0

Hi,

 

Try this

 

-d '{  "extattrs": { "Asset_Tag": {  "value": "W27617"}}}'

Re: MAC Filter - add Extended Attribute Values

Techie
Posts: 11
10406     0

I'm still not doing it correctly - getting this response:

-d : The term '-d' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.

 

Here's a code snippet:

$uri = "$uri_base/macfilteraddress?_return_type=json-pretty&filter=Kelly_MAC&mac=11:22:33:44:55:66"

 

 

$results = Invoke-RestMethod -Uri $uri -Credential $credential -Method Get -SessionVariable ib_session
$obj_type = $results._ref
$uri_base = "$grid_master/wapi/$wapi_ver"
$uri = "$uri_base/$obj_type"

 

$json = -d '{  "extattrs": { "Asset_Tag": { "value": "W27617"}}}'

 

$result_ref = Invoke-RestMethod -Uri $uri -ContentType application/json -Method Post -WebSession $ib_session -Body ([System.Text.Encoding]::UTF8.GetBytes($json))

Re: MAC Filter - add Extended Attribute Values

Adviser
Posts: 200
10406     0
You don’t issue the “-d” in the JSON text. That’s a command for CURL which places that text into the body.

With PowerShell, you need to put that data into the body of the message on the Invoke-RestMethod line. Refer to the Samples.PS1 file (look at the bottom) here (https://github.com/Ameritus/PowerShell/tree/master/Infoblox-DDI).

It’s not a full function yet but I’m working on it occasionally and reposting updates to https://github.com/Infoblox-API/PowerShell.

Re: MAC Filter - add Extended Attribute Values

Techie
Posts: 11
10406     0

Finally, success!  Here's what worked - I changed the method to Put:

 

$uri = "$uri_base/macfilteraddress?_return_type=json-pretty&filter=Kelly_MAC&mac=11:22:33:44:55:66"

 

$json =  '{"extattrs":{"Asset_Tag":{"value":"W27617"},"DataSource":{"value": "Manual"},"DateAdded":{"value": "2016-09-28T11:01:00Z"},"Host_ID": {"value": "W6FYYH72"}}}'

 

$result_ref = Invoke-RestMethod -Uri $uri -ContentType application/json -Method Put -WebSession $ib_session -Body ([System.Text.Encoding]::UTF8.GetBytes($json))

Showing results for 
Search instead for 
Did you mean: 

Recommended for You