Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2018-07-03 05:52 AM
Hello!
Recently, I've faced a report in Archer, that have a lot of records. So, in API request i need to make several requests with different page numbers.
I'm using powershell, and this is my search function:
function Search($session_token, $reportGUID) {
$api_url = $base_url + "/ws/search.asmx"
try {
$ws = New-WebServiceProxy -Uri $api_url -Class Search -Namespace webservice
$page = 1
Do {
[xml] $xdoc = $ws.SearchRecordsByReport($session_token, $reportGUID, $page)
$xml_file += $xdoc.InnerXml
$page++
} While ($xdoc.Records.Record.Count -gt 0)
}
catch {
Error -exception $_.Exception
}
return $xml_file
}
Search itself work great, but in result I have invalid xml file. It contains multiple xml declarations, field descriptions, etc. (because of multiple pages in report, i suppose).
So, anyone faced same issue?
How to properly get all of the records from report without extra information?
2018-07-18 01:32 AM
To return proper XML, with field definitions and etc., I've updated function.
function Error($exception) {
$exception | Format-List -Force
exit
}
function SearchRecordsByReport($session_token, $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)) | Out-Null
}
}
$page++
} While ($xdoc.Records.Record.Count -gt 0)
}
catch {
Error -exception $_.Exception
}
return $xml_file.InnerXml
}
2018-07-06 03:36 AM
If anyone faces same issue, here is my updated function.
Basically, instead of adding whole XML text of the response, I'm merging only records itself.
function Search($session_token, $reportGUID) {
$api_url = $base_url + "/ws/search.asmx"
$xml_file = New-Object System.Xml.XmlDocument
$xml_file.LoadXML("<Records></Records>")
try {
$ws = New-WebServiceProxy -Uri $api_url -Class Search -Namespace webservice
$page = 1
Do {
[xml] $xdoc = $ws.SearchRecordsByReport($session_token, $reportGUID, $page)
ForEach ($record in $xdoc.SelectNodes("/Records/Record")) {
$records = $xml_file.SelectSingleNode("/Records")
$records.AppendChild($xml_file.ImportNode($record, $true)) | Out-Null
}
$page++
} While ($xdoc.Records.Record.Count -gt 0)
}
catch {
Error -exception $_.Exception
}
return $xml_file.InnerXml
}
2018-07-18 01:32 AM
To return proper XML, with field definitions and etc., I've updated function.
function Error($exception) {
$exception | Format-List -Force
exit
}
function SearchRecordsByReport($session_token, $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)) | Out-Null
}
}
$page++
} While ($xdoc.Records.Record.Count -gt 0)
}
catch {
Error -exception $_.Exception
}
return $xml_file.InnerXml
}
2019-04-09 03:46 AM
Hi Sergei Bakhaev,
We tried executing the above code but are unable to retrieve the location of the returned file.
2019-04-10 11:49 PM
2019-04-19 02:27 AM
You need to call save method on the XmlDocument object.
https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=netframework-4.8
2019-05-01 01:17 PM
I am able to see all the records on the console. However, I am unable to save them to a file. It is only saving the header (page 2 of the response - which has only the header)
try
{
$api_url = $base_url + "/ws/search.asmx"
$ws = New-WebServiceProxy -Uri $api_url -Class Search -Namespace webservice
$page = 1
$xml_file = New-Object System.Xml.XmlDocument
Do
{
"Page " + $page
[xml] $xdoc = $ws.SearchRecordsByReport($session_token, $searchXml, $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)) | Out-Null
}
}
$v= $xdoc.InnerXml
Write-Host "xml file = $v"
$v |Out-File "c:\test\Archer1.xml"
$page++
}
While ($xdoc.Records.Record.Count -gt 0)
}
catch
{
Error -exception $_.Exception
}
2019-05-02 08:04 PM
Hi Sergei
The code snippet
{
return $xml_file.InnerXml
}
still contains multiple xml declarations, field descriptions, etc.