I figured it out so am posting the code to help others:
$FileCounter = 1;
$StartIndex = 1;
$PageSize = 2000;
$totalresultcount = $StartIndex;
$RallyType = "UserStory";
$FileName = $RallyType+$FileCounter+".json";
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
While($StartIndex -le $totalresultcount) {
Invoke-RestMethod -Method get -Uri "https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?pagesize=$PageSize&start=$StartIndex&fetch=Blocked,BlockedReason,CreationDate,DirectChildrenCount,DisplayColor,FormattedID,HasParent,InProgressDate,LastUpdateDate,Name,ObjectID,PlanEstimate,PlannedDeploymentDate,ProductionDate,Program,Rank,Ready,ScheduleState,TaskActualTotal,TaskEstimateTotal,TaskRemainingTotal,TaskStatus,UserStoryType,Feature,Iteration,Owner,Parent,PortfolioItem,Milestones,Tags,Risks" -headers @{"ZSESSIONID" = '<key here>'} -outfile $FileName
$content = Get-Content $FileName
$contentobj = ConvertFrom-Json -InputObject $content
$totalresultcount = $contentobj.QueryResult.TotalResultCount;
$StartIndex = $StartIndex + $PageSize;
$FileCounter = $FileCounter + 1
$FileName = $RallyType+$FileCounter+".json";
}
As an FYI - I take the files produced by this script and load them into an Oracle table by using sqlldr then use the JSON_TABLE command (in oracle) to parse the JSON date into a table. If anyone would find that code helpful i will post.
Original Message:
Sent: 07-09-2019 04:58 PM
From: Bob H
Subject: Powershell Invoke_RestMethod to WSAPI SSO
thanks to you both. I wonder if either of you have already built PS code that loops when the TotalResultCount value exceeds the 2000 PageSize limit? That is, i know there are currently 16,000+ records in my in the result set and i'd like to create 8 output files with 2000 records each. I see the 16,000+ value come back in the TotalResultCount field from the first call, and as such know i have to make 7 more calls (incrementing the StartIndex) to get the rest of the data.
Thanks!
Original Message:
Sent: 07-09-2019 04:06 PM
From: Bob H
Subject: Powershell Invoke_RestMethod to WSAPI SSO
Thank you - that worked!!
Original Message:
Sent: 06-28-2019 01:26 PM
From: David LeDeaux
Subject: Powershell Invoke_RestMethod to WSAPI SSO
Hi Bob,
Can you try passing the following header:
ZSESSIONID : <your API key>
Original Message:
Sent: 06-28-2019 01:24 PM
From: Bob H
Subject: Powershell Invoke_RestMethod to WSAPI SSO
Hi-
I've been struggling to get a simple powershell script to call the Rally REST APIs to retrieve JSON files. Any insight/help from the community would be greatly appreciated.
First let me state that my organization uses SSO for access into rally. As such, I've created an API key with full access.
When I run this script in powershell:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-RestMethod -Method get -Uri "
https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?pagesize=500&start=1&fetch=Blocked,BlockedReason,CreationDate,DirectChildrenCount,DisplayColor,FormattedID,HasParent,InProgressDate,LastUpdateDate,Name,ObjectID,PlanEstimate,PlannedDeploymentDate,ProductionDate,Program,Rank,Ready,ScheduleState,TaskActualTotal,TaskEstimateTotal,TaskRemainingTotal,TaskStatus,UserStoryType,Feature,Iteration,Owner,Parent,PortfolioItem,Milestones,Tags,Risks" -headers @{"X-APIKEY" = "the key i got from rally website here"}
I get:
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:2 char:2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (
System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I've tried multiple variants of 'headers' based on google searches but can't get anything to work.
Note: If i input that same URL in my browser (without the headers option) after I SSO, everything works fine.
Thanks in advance for any help.
Bob
------------------------------
Bob H
------------------------------