Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2022-07-06 11:57 AM
Before I start, I am very new to API coding.
I am trying to pull mobile numbers of users from a report. I am using the below code:
$base_url = "http://serverIP/"
$instance_name = ""
$user_domain = ""
$username = "uname"
$password = "pwd"
$sessiontoken = ""
$reportguid = "12345678"
try{ $api_url = $base_url + "/ws/general.asmx"
if ($user_domain -eq "") {
$ws = New-WebServiceProxy -Uri $api_url -Class General -Namespace webservice -ErrorAction Stop
$sessiontoken = $ws.CreateUserSessionFromInstance($username, $instance_name, $password)
}
else {
$ws = New-WebServiceProxy -Uri $api_url -Class General -Namespace webservice -ErrorAction Stop
$sessiontoken = $ws.CreateDomainUserSessionFromInstance($username, $instance_name, $password, $user_domain)
}
$sessiontoken
}
catch {
$sessiontoken = $null
$_.Exception|Format-List -Forceexit}function Error($exception) {
$exception | Format-List -Force
#exit
}
function SearchByReport() {
[CmdletBinding()] param([Parameter(Mandatory)][string]$session_token,[Parameter(Mandatory)][string]$reportGUID)
$api_url = $base_url + "/ws/search.asmx"
$xml_file = New-Object System.Xml.XmlDocument
try {
$ws = New-WebServiceProxy -Uri $api_url -Class Search -Namespace webservice
$page = 1
Do {
[xml] $xdoc = $ws.SearchRecordsByReport($session_token, $reportGUID, $page)
if ($page -eq 1) {
$xml_file = $xdoc
}
else {
ForEach ($record in $xdoc.SelectNodes("/Records/Record")) {
$records = $xml_file.SelectSingleNode("/Records")
$records.AppendChild($xml_file.ImportNode($record, $true))
}
}
$page++
}
While ($xdoc.Records.Record.Count -gt 0)
}
catch {
Error -exception $_.Exception
}
$xml_file.InnerXmlreturn
$xml_file.InnerXml
}
$testing = SearchByReport -session_token $sessiontoken -reportGUID $reportguid
This code doesn't throw any error, however returns blank. On another community post, the solution suggested to a similar problem was that to ensure the report is a statistical report. In my case, it's a statistical report, and the report ID, and other details are correct.
Some advice would be really helpful.