function Get-VismaRecords {
$VismaRecords = @()
$VismaURI = "https://datahub.vismaenterprise.dk/datahub/V2/mainservice.svc/Employee?`$select=FirstName,SocialSecurityNumber&subscription-key=API-key"
do {
$VismaData=Invoke-WebRequest -Method GET -Uri $VismaURI -UseBasicParsing
[xml]$XMLVismaData = $VismaData.Content
$XMLVismaData.feed.entry | % {
$obj = New-Object PSObject
#Add properties to the object
$obj | Add-Member -MemberType NoteProperty -Name "SocialSecurityNumber" -Value $_.content.properties.SocialSecurityNumber.'#text'
$obj | Add-Member -MemberType NoteProperty -Name "FirstName" -Value $_.content.properties.FirstName.'#text'
#Return the object
$VismaRecords += $obj
}
#Check for the skiptokenID
$skiptoken = $XMLVismaData | Select-Xml -Namespace @{default="http://www.w3.org/2005/Atom"} -XPath "//default:link[@rel='next']/@href" | % {($_.Node.Value -split "skiptoken=" | Select -Last 1).Trim("'")}
if ($skiptoken) {
$VismaURI = "https://datahub.vismaenterprise.dk/datahub/V2/mainservice.svc/Employee?`$select=FirstName,SocialSecurityNumber&`$skiptoken='$skiptoken'&subscription-key=API-key"
}
} while ($skiptoken)
return $VismaRecords
}
#Ouput # of records
(Get-VismaRecords).count
#Output all returned data
Get-VismaRecords I just wanted to share this code on how to retrieve data from the API using PowerShell. Finding the solution and asking for support from Datahub gave me quite a headache. Please note: the SkiptokenID is only returned when using Invoke-WebRequest, not with Invoke-RestMethod. I hope this helps a lot of developers who are new to Visma Datahub like me. Cheers!
... View more