THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

Restarting Infoblox using API giving error

Techie
Posts: 7
5224     2

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.

Re: Restarting Infoblox using API giving error

Superuser
Posts: 38
5224     2

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

Shukran

Re: Restarting Infoblox using API giving error

Techie
Posts: 7
5224     2

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

Superuser
Posts: 38
5224     2

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)

Shukran

Re: Restarting Infoblox using API giving error

Techie
Posts: 7
5224     2

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

Superuser
Posts: 38
5224     2

If you run the query using an API client does it go through?

Shukran

Re: Restarting Infoblox using API giving error

Techie
Posts: 7
5224     2

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

Superuser
Posts: 38
5224     2

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")
}

Shukran

Re: Restarting Infoblox using API giving error

Moderator
Moderator
Posts: 321
5224     2

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

New Member
Posts: 1
5225     2

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

Moderator
Moderator
Posts: 321
5225     2

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.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You