Mine produkter
Hjælp

Adgang til Visma Enterprise DataHub API V2

19-10-2022 15:49 (Senest opdateret 09-01-2024)
  • 2 Svar
  • 0 ros
  • 857 Visninger

Introduktion
Dette dokument beskriver, hvordan man kan tilgå Visma Enterprise DataHub API – V2.

Kommentarer
MrX007
CONTRIBUTOR *
af MrX007 (Opdateret ‎15-04-2024 06:13 af MrX007 )

 

 

 

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!

 

Thu Nguyen
VISMA
af Thu Nguyen

Hi @MrX007 

 

Thank you for sharing and for letting us know! We'll make sure to update our documentation accordingly. If you have any further questions or feedback, feel free to reach out.

 

Best regards

Thu

Bidragydere