#####User details here##### #Givenergy Portal API Key Goes Below between " " $GivEnergyPortalAPI = "489f5bcf101a___OLD_INVERTER_KEY_HERE__3187cbe1" $InvSN = "SD___SERIAL_HERE__078" $StartYear = 2021 $StartMonth = 4 $StartDay = 1 ##Repeat Data Pull Increment for X days $repeatFor = 4 ##Sets Delay intervals (in Seconds) between calls. Beware you may get IP banned if you pull hundreds of calls with short intervals. $refresh = "10" ########end user input############# ##Login to Old API ## $Giv_En = Invoke-WebRequest -Method 'Post' -Uri https://www.givenergy.cloud/GivManage/login/authKey?authKey=$GivEnergyPortalAPI -SessionVariable session $Giv_En.Content | Out-File -FilePath.\Login.txt Write-Output "Login Response Saved to: Login.txt" ##Run first Call to create the file first## $StartPoint = $StartDay $Giv_En_Chart = Invoke-WebRequest -Method 'Post' -Uri https://www.givenergy.cloud/GivManage/invData/$InvSN/$StartYear-$StartMonth-$StartDay"?page=1&rows=301" -WebSession $session $Giv_En_Chart.Content | Out-File -FilePath .\DataDay$StartDay.txt Out-File -FilePath .\DataTotals.txt Write-Output "Data Saved to: DataDay$StartDay.txt" ##Wrap whole script in a "while" to force it to loop (Powershell has no "goto" etc...)for as many loops as needed before end day while (1) { $Giv_En_Chart = Invoke-WebRequest -Method 'Post' -Uri https://www.givenergy.cloud/GivManage/invData/$InvSN/$StartYear-$StartMonth-$StartDay"?page=1&rows=301" -WebSession $session $Giv_En_Chart.Content | Out-File -FilePath .\DataDay$StartDay.txt $JSON = Get-Content .\DataDay$StartDay.txt | ConvertFrom-Json $Rows = ForEach($Row in $JSON.rows[0]) { For($i = 0; $i -lt $JSON.rows.Length; ++$i ) { Write-Output $JSON.rows[$i] | Add-Content -Path .\DataTotals.txt } } Write-Output "Latest Data Added to: DataTotals.txt" ##Increment Day by 1 $StartDay++ ##this Runs on end Loop Only if ($StartDay -eq ($StartPoint + $repeatFor)){ Write-Output "All done - Exit in 5...." start-sleep -s 5 Exit ##end loop } Write-Output "Sleeping for $refresh Sec before refresh. Next pull is for day: $StartDay" start-sleep -s $refresh }