Developmentish

June 2, 2014

PowerShell + BusinessObjects REST Api #2: Getting a list of documents

Filed under: Business Objects, Powershell, REST API, Uncategorized — Martyn Gough @ 3:00 pm

Today we’re going to follow on from the first lesson: Logging on and off of SAP BusinessObjects using PowerShell and the RESTful API.

This is a simple request to send however we need to handle the response as the Raylight SDK will only return results in batches of up to 50.

$DocRequestUri         = "http://BOEServer:6405/biprws/raylight/v1/documents?offset=0&limit=10"            
$DocRequestHeaders     = @{"Accept" = "application/json";"Content-Type" = "application/json";"X-SAP-LogonToken" = $LogonToken}            
            
(Invoke-RestMethod -Method GET -Uri $DocRequestUri -Headers $DocRequestHeaders).documents.document | Format-Table

As we can see above, our web service URL contains 2 parameters… Offset and Limit…
Limit is the number of results returned by the GET request [1-50]
Offset is the starting point in the result list.

In English, offset=0&limit=50 will return results 1-50… offset=150&limit=20 will return results 150-170.

So if we lob this all together with our login script we’ve got something that’ll return us a list of documents in BusinessObjects in a tabular format.

#########################################################################################################################################################            
# Log on to BI platform            
            
$LogonRequestUri       = "http://BOEServer:6405/biprws/logon/long"            
$LogonRequestHeaders   = @{"Accept" = "application/json";"Content-Type" = "application/json"}            
            
$LogonInfo             = @{}            
$LogonInfo.userName    = "developmentish"               
$LogonInfo.password    = "Password"            
$LogonInfo.auth        = "secEnterprise"              
$Logon                 = ($LogonInfo | ConvertTo-Json)            
            
$LogonToken            = "`"" + (Invoke-RestMethod -Method POST -Uri $LogonRequestUri -Headers $LogonRequestHeaders -Body $Logon).logonToken + "`""            
            
#########################################################################################################################################################            
# Get a list of documents            
            
$DocRequestUri         = "http://BOEServer:6405/biprws/raylight/v1/documents?offset=0&limit=10"            
$DocRequestHeaders     = @{"Accept" = "application/json";"Content-Type" = "application/json";"X-SAP-LogonToken" = $LogonToken}            
            
(Invoke-RestMethod -Method GET -Uri $DocRequestUri -Headers $DocRequestHeaders).documents.document | Format-Table            
            
#########################################################################################################################################################            
# Log off of BI Platform            
            
$LogoffRequestUri      = "http://BOEServer:6405/biprws/logoff"            
$LoggoffRequestHeaders = @{"Accept" = "application/json";"X-SAP-LogonToken" = $LogonToken}            
            
Invoke-RestMethod -Method POST -Uri $LogoffRequestUri -Headers $LoggoffRequestHeaders             
            
#########################################################################################################################################################            
            

Enjoy!

Create a free website or blog at WordPress.com.

Design a site like this with WordPress.com
Get started