- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 10:28 PM
Hi,
I am trying to restart Infoblox using API endpoint {restartservices} after fixing IP but I am getting an error [The remote server returned an error: (400) Bad Request.]
Any help would be greatly appriciated.
Thank you.
Solved! Go to Solution.
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 08:09 AM
Hi Sidko,
If you are trying to restart the grid you can append '_function=restartservices' to your api request
Below is a sample curl
curl -L -X POST 'https://<grid_ip>/wapi/v2.12/grid/<grid_ref>?_function=restartservices' -H 'Authorization: Basic YWRtaW46aW5mb2Jsb3g='
Regards,
Shukran
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2022 11:14 PM
Hi shukran,
Thank you for your reply.
I am using powershell
The url used
https://<IP>/wapi/v2.4/grid/<grid_ID>?_function=restartservices
I am able to raise other API request, I am only facing issue while restarting.
Regards,
Sidko
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 08:37 AM
Could you share the query you are trying to run in Powershell. Also could you try running it using some API client (like Postman or Insomnia)
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 11:57 PM
Hi shukran,
URL used: https://<IP>/wapi/v2.4/grid/<grid_ID>?_function=restartservices
$host_details = [ordered]@{
memberOrder="GROUPED"
requestType=“RESTART_IF_NEEDED"
serviceOption="ALL"
}
$body = $host_details | ConvertTo-Json
$response = Invoke-WebRequest -Uri $url -Method POST -Credential $creds -ContentType 'application/json' -Body $body -UseBasicParsing
Error:[The remote server returned an error: (400) Bad Request.]
I am able to run other API services using powershell its only giving me error while restarting it.
Regards,
Siddhant
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 02:36 AM
If you run the query using an API client does it go through?
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 03:10 AM
Its on clients onframe server I have tried postman on avalable brousers (firefox,IE) but looked like it didn't support these brousers.
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 06:04 AM
I think the issue may be because of the host details that you have entered.
member order and service option are deprecated and i have updated them with new parameters
also the request type option is not correct.
Could you use the below host details and try running it.
$host_details = [ordered]@{
mode="GROUPED"
restart_option="RESTART_IF_NEEDED"
services=@("ALL")
}
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 08:22 AM
Try this, for initiating the restart:
$niosip = "192.168.1.2" $niosuser = "admin" $niospw = "infoblox" $wapiver = "v2.10" $resturl = 'https://' + $niosip + '/wapi/' + $wapiver + '/request' $resturl $data = ' [ { "method":"GET", "object":"grid", "assign_state": {"grid_ref": "_ref" }, "enable_substitution": true }, { "method":"POST", "object": "##STATE:grid_ref:##", "enable_substitution": true, "args":{"_function":"restartservices"}, "data":{ "mode":"GROUPED", "restart_option":"RESTART_IF_NEEDED" } } ]' $json = $data | ConvertTo-Json $json $cred = New-Object PSCredential $niosuser, ($niospw | ConvertTo-SecureString -AsPlainText -Force) add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class IDontCarePolicy : ICertificatePolicy { public IDontCarePolicy() {} public bool CheckValidationResult( ServicePoint sPoint, X509Certificate cert, WebRequest wRequest, int certProb) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy $out = Invoke-RestMethod -Uri $resturl -Method Post -Credential $cred -Body $data -ContentType 'application/json'
And try this to monitor the restart status of all the appliances:
$niosip = "192.168.1.2" $niosuser = "admin" $niospw = "infoblox" $wapiver = "v2.10" $resturl = 'https://' + $niosip + '/wapi/' + $wapiver + '/request' $resturl $data = ' [ { "method":"GET", "object":"grid", "assign_state": {"grid_ref": "_ref" }, "enable_substitution": true }, { "method":"POST", "object": "##STATE:grid_ref:##", "enable_substitution": true, "args":{"_function":"restartservices"}, "data":{ "mode":"GROUPED", "restart_option":"RESTART_IF_NEEDED" } } ]' $json = $data | ConvertTo-Json $json $cred = New-Object PSCredential $niosuser, ($niospw | ConvertTo-SecureString -AsPlainText -Force) add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class IDontCarePolicy : ICertificatePolicy { public IDontCarePolicy() {} public bool CheckValidationResult( ServicePoint sPoint, X509Certificate cert, WebRequest wRequest, int certProb) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy $out = Invoke-RestMethod -Uri $resturl -Method Post -Credential $cred -Body $data -ContentType 'application/json'
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2024 09:51 PM
I can't say HOW long been searching for just the data provided in this post! It was exactly what I needed. Thank-you.
I have to admit not fully understanding the format of the $data. Nor have I found where this method of combining request into a single Invoke-RestMethod is documented. Most of the threads I found covered passing the params as a "-Form". Which PowerShell v5.1 doesn't do so well. I was worried my project was going to require PowerShell Core 7+.
Question. Why convert $data ot JSON and then not use it within the Invoke-RestMethod? Is it because Invoke-RestMethod is expecting a hash object and does the conversion under the "covers".
Re: Restarting Infoblox using API giving error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 05:24 AM
Yes, you're correct. "$data" is a pure text string, whereas "$JSON" is a JSON object.
Us humans like to read & write strings, whereas Invoke-RestMethod expects a JSON object as input.