Forum Discussion
hoaphan
4 years agoNew Contributor III
REST API USE
Hello OneStream Community, I'm working on how to implement a REST API in OS, but i'm not sure to understand all the steps, i've already read the documentation and i've found it very hard to unders...
- 1 year ago
Ahhh, thank you CoPilot. I got it to work with this code:
Private Function GetSourceDataREST(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Transformer) As DataTable Try Dim strEntityWF As String = api.WorkflowProfile.Name.Split(".")(0) ' Use already encoded credentials (eg.,In Postman) key Dim wdCreds As String = "<CREDENTIALS>" 'Call the REST API Dim wc As New WebClient wc.Encoding = Encoding.UTF8 wc.Headers("cache-control") = "no-cache" wc.Headers("ContentType") = "application/json" wc.Headers("Accept") = "application/json" wc.Headers("Authorization") = "Basic " & wdCreds Dim jsonURL As String = "<AURL>" Dim json As String = wc.DownloadString(jsonurl) Dim pullData As DataTable = ParseJsonToDataTable(json, strEntityWF) 'Close Web connection wc.dispose 'Return the dataset Return pullData Catch ex As Exception Throw ErrorHandler.LogWrite(si, New XFException(si, ex)) End Try End Function Function ParseJsonToDataTable(json As String, EntityName As String) As DataTable Dim dataTable As New DataTable() dataTable.Columns.Add("entity", GetType(String)) dataTable.Columns.Add("displayName", GetType(String)) dataTable.Columns.Add("amount", GetType(Integer)) Dim jObject As JObject = JObject.Parse(json) Dim dataArray As JArray = jObject("employees") For Each item As JObject In dataArray Dim row As DataRow = dataTable.NewRow() row("entity") = EntityName row("displayName") = item("displayName") row("amount") = 1 dataTable.Rows.Add(row) Next Return dataTable End Function
Sridhar_M
3 years agoContributor
Thank you Sai for sharing the snippet. This is really helpful.
I've a question, your using this connector to load directly to a register table ? If yes May I know how your calling this business rule ?
Sai_Maganti
3 years agoContributor II
Sridhar
I used this in a connector BR to import FTE actuals from workday.
Best
Sai
- Sridhar_M3 years agoContributor
Got it, Thank you Sai
Related Content
- 4 months ago
- 2 years ago
- 4 years ago