Question
Russell Preston · Jun 13

Connecting to Existing REST API without writing a Class

Hello everyone,

I would like to know if it is possible to connect to a REST API through production, without having to write a class that extends %CSP.REST. Is there a GUI based way where I can configure my GetRest and then use EnsLib.REST.GenericService and EnsLib.REST.GenericOperation to configure my production and perform transformations? 

Product version: IRIS 2021.2
0
1 157
Discussion (10)2
Log in or sign up to continue

Yes, the GenericService will send an EnsLib.HTTP.GenericMessage object to your business process. The GenericMessage includes the headers and content of the inbound HTTP request. Your DTL can use these fields to transform to another format.

Similarly, the GenericOperation accepts the same GenericMessage type and uses the values in it to issue an HTTP request to the downstream system.

So all together, this allows you to create a REST web service and/or call out to external REST services using only the GUI.

https://docs.intersystems.com/irisforhealth20221/csp/docbook/DocBook.UI....

Thank you, Marc, and if I needed to do more, I would create my SSL/TLS Configuration and OAuth 2.0 Client configuration and link those to my production?

Thank you Marc, maybe to help with a little guidance, I'm trying to connect to this REST API. https://docs.athenahealth.com/api/api-ref/appointment-slot#Get-list-of-o... 

I have my client ID, secret, and everything else. I'm just curious about what is needed for me to build this GUI side. Would the steps be, to build my Server Description, then the client config, then my production? I'm just not sure how to link those configurations to my business service.

For the outbound REST calls, I would typically create a custom operation class that calls methods in %SYS.OAuth2.* to fetch a token from the downstream system and then places that in the HTTP header.

If it's essential for you to avoid creating a custom class, you could call the %SYS.OAuth2 methods from a BPL and then add the token to the header fields in the EnsLib.HTTP.GenericMessage that you send to the GenericOperation.

You haven't said what needs to happen between the business service and business operation, so it's hard to discuss how everything fits together as you asked.

Thanks Marc, we would like to call out the Business service to get the available slots from the private API listed above, from there we would then like to take that JSON payload from the API listed above and transform the JSON to our desired format and the newly transformed payload be sent to our external application.

Ok, so the flow would look roughly like this:

  • The GenericService accepts an inbound REST request, populates a GenericMessage, and sends it to your business process
  • Business process extracts the JSON payload from the GenericMessage, and pulls out any relevant details needed for the call to Athena
  • Business process creates a new GenericMessage, populates any items needed by Athena, uses %SYS.OAuth2 (and the OAuth client profile you created) to request an OAuth token and adds it to the GenericMessage, and passes the new GenericMessage to the business operation.
  • Business operation makes the outbound REST call to Athena, and returns a new GenericMessage containing the response to your business process.
  • Business process extracts JSON payload from the GenericMessage, uses a transformation to create the payload required by your internal REST client.
  • Business process creates a new GenericMessage, populates it with the response payload, and returns it to the GenericService
  • GenericService returns response to REST client

Hello,

In addition to the previous answers,  there is the zpm module OpenApi Client Gen in order to generate an Objectscript client (with or without interoperability production) from a swagger 2.0 file.

Thank you, Lorenzo, I tried that, but the documentation for the API set that I am trying to connect to uses Swagger 3.0