cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
429
Views
7
Helpful
3
Replies
Beginner

PI 3.2, Problem with device bulkimport with API

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

3 REPLIES 3
Highlighted
Cisco Employee

Re: PI 3.2, Problem with device bulkimport with API

That error message indicates there's a problem in your script, specifically the print command which (I believe) intends to send things to an actual printer device.  If you're using PowerShell, you probably want to use Write-Host or something like that instead.

Beginner

Re: PI 3.2, Problem with device bulkimport with API

No, sorry, the print is only here to print the error returned by the server, in this case, "Unable to initialize device PRN"

Without the print I have an (500) Internal Server Error Returned by PI.

Any other idea ? Or something missing ? Or Bug on PI side ?

Beginner

Re: PI 3.2, Problem with device bulkimport with API

Hi,

I still have this problem, eaven in Pi 3.4... and even if I remove the try/catch command or use a writ-host...

 

The error is :

{"errorDocument":{"httpResponseCode":500,"httpMethod":"PUT","message":"com.fasterxml.jackson.core.JsonParseException: Unknown DTO type: deviceImport\n at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@595371a8; line: 12, column: 1]","exception":"javax.ws.rs.InternalServerErrorException: com.fasterxml.jackson.core.JsonParseException: Unknown DTO type: deviceImport\n at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@595371a8; line: 12, column: 1]","uriPath":"op/devices/bulkImport","queryParams":"{}","domain":"ROOT-DOMAIN"}}

 

 

And now, a new comment has been added in the API documentation, that was not here before... :

TL1 Credentials Support

  • Transaction Language 1 (TL1) credentials are not currently supported for this operation.

As I have this line in the script :

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

 

How can we do to have this operation working without TLS1 ?? (Also not working with SSL3...) 

Or any other help will be apreciated

Content for Community-Ad
August's Community Spotlight Awards