2 Replies Latest reply: Nov 30, 2017 10:37 PM by nicolassadeg RSS

PI 3.2, Problem with device bulkimport with API

nicolassadeg

Hi all,

 

I'm trying to add devices with the API, with powershell script.

With credential profile or not, I alwayse have an error returned : Unable to initialize device PRN

Looks like there is something missing in ma parameters.

 

Script is this one :

 

$CiscoPIServer='10.10.30.231'

$CiscoPIUser = 'CiscoPI'

$CiscoPIPwd =  'Password'

 

$url = "https://$CiscoPIServer/webacs/api/v3/"

 

add-type @"

    using System.Net;

    using System.Security.Cryptography.X509Certificates;

    public class TrustAllCertsPolicy : ICertificatePolicy {

        public bool CheckValidationResult(

            ServicePoint srvPoint, X509Certificate certificate,

            WebRequest request, int certificateProblem) {

            return true;

        }

    }

"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

 

$Encoded = [System.Text.Encoding]::UTF8.GetBytes("$($CiscoPIUser):$($CiscoPIPwd)")

$EncodedPassword = [System.Convert]::ToBase64String($Encoded)

$headers = @{"Authorization"="Basic $($EncodedPassword)"}

 

# Method type

$Method = "PUT"

 

$Resource = "op/devices/bulkImport.json"

 

 

$credentialProfileName = "ProfileName"

$ipAddress = "10.10.10.10"

$SNMPPort = "161"

$SNMPReadComm = "SNMPReadComm"

$SNMPWriteComm = "SNMPWriteComm"

$SNMPRetries = "2"

$SNMPTimeout = "30"

$SNMPVersion = "2c"

$protocol = "SSH2"

$cliTimeout = "40"

$cliUsername = "cliUsername"

$cliPassword = "cliPassword"

$cliEnablePassword = "cliEnablePassword"

$httpPort = "80"

$ufdname = "AutoImport"

$udfvalue = "ByOrchestrator"

 

$udf1 = [PsCustomObject] @{

    "name" = $ufdname

    "value" = $udfvalue

}

 

$Device1 = [PsCustomObject] @{

   

    #"credentialProfileName" = $credentialProfileName

    "ipAddress" = $ipAddress

    "snmpPort" = $SNMPPort

    "snmpReadCommunity" = $SNMPReadComm

    "snmpWriteCommunity" = $SNMPWriteComm

    "snmpRetries" = $SNMPRetries

    "snmpTimeout" = $SNMPTimeout

    "snmpVersion" = $SNMPVersion

    "protocol" = $protocol

    "cliTimeout" = $cliTimeout

    "cliUsername" = $cliUsername

    "cliPassword" = $cliPassword

    "cliEnablePassword" = $cliEnablePassword

    "httpPort" = $httpPort

    "udfs" = [PsCustomObject] @{ "udf" = @($udf1) }

}

 

$Fullobject = [PsCustomObject] @{

    "deviceImport" = [PsCustomObject] @{       

        "devices" = [PsCustomObject] @{ "device" = @($Device1) }

    }

}

$body = $Fullobject | ConvertTo-Json -Depth 10

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 

try {

    $Result = Invoke-RestMethod -Method $Method -Uri $url/$Resource -Headers $headers  -Body $body -SessionVariable session -ContentType application/json

    }

catch [Exception] {

    print $_

}

 

 

On the parameters given, I use Credential profile with IP address or IP address without profile and all other detailed field. Alwayse the same error returned