If you want to create a direct connection between your source systems and the OneStream environment without the need of creating difficult network connections or maintenance dependent IP whitelisting, REST API is your friend. More and more, our customers are using REST API technology to automate their data integration, making processes faster and simpler. The RESTful API, or REST API, uses HTTP requests to communicate directly to other webservices out-of-the-box. So no additional changes in the network are needed to facility this connection!
In order to make use of the REST Ful API technology within the OneStream platform, one can create an Extensibility Business Rule that executes these requests.
REST Request
See the following code snippet which represents an example for a parameterized REST API POST request:
Using client As New HttpClient()
‘ Set authorization header
client.DefaultRequestHeaders.Add("Authorization", "Bearer " & sBearerToken)
' Create request body
Dim dRestAPIParameters As New Dictionary(Of String, Object)()
dRestAPIParameters.Add("Period", "2024M10")
dRestAPIParameters.Add("Entity", "Groningen")
' Convert the request body to the correct format, application/json in UTF8
Dim jsonRestAPIParameters As String = JsonConvert.SerializeObject(dRestAPIParameters)
Dim content As New StringContent(jsonRestAPIParameters, Encoding.UTF8, "application/json")
'Send POST request
Try
Dim response As HttpResponseMessage = client.PostAsync(url, content).Result
'If the request is successful
If response.IsSuccessStatusCode Then
Dim responseBody As String = response.Content.ReadAsStringAsync().Result
If responseBody.Length > 0 Then
Return JObject.Parse(responseBody)("Status")
Else 'responseBody.Length > 0
Throw New XFException($"{response.StatusCode} - {response.ReasonPhrase}")
Return Nothing
End If 'responseBody.Length > 0
'If the request fails
Else 'response.IsSuccessStatusCode
Throw New XFException($"{response.StatusCode} - {response.ReasonPhrase}")
Return Nothing
End If 'response.IsSuccessStatusCode
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Using 'client As New HttpClient()
The POST request can act as a trigger to generate a certain dataset based on the parameters that are forwarded in the request. After this dataset is generated, a GET REST API can be used to obtain the actual dataset in JSON format and directly import it into the OneStream Import steps of your Workflows .
Security
The obvious downfall to this REST API is that it is exposed directly to the internet, making the importance of having a secure connection of vital importance. A simple native username and password (Basic Authentication header) may be no longer sufficient. For our customers, we’ve configured OneStream to make use of better authentication methods to authenticate REST API requests.
An example of these methods is the OAUTH 2.0 protocol. This makes us of a so called authentication token, which enables users to access APIs without having to enter their login credentials each time they visit. In order to obtain the OAuth authentication token the same extensibility business rule can be used, in which a basic username and password is passed to ultimately receive a token. This token string can then be used as a Bearer Token property in the authorization header of the original request. The snippet below represents an example of a REST API POST request, in which the response contains the generated OAUTH access token.
https://pastebin.com/embed/PpksGH9y
<script src="https://pastebin.com/embed_js/PpksGH9y"></script>
This is just an example of REST API within OneStream. The possibilities of integrating RESTful technology within the OneStream platform are limitless.
Conclusion
If you are fed up of transferring manual csv files from system to system and want to know more about the possibilities of REST API together with OneStream for automating the integration, please do not hesitate to contact me or my colleagues.