How to dynamically set host for REST Service / SmartObject

  • 16 December 2021
  • 2 replies
  • 12 views

Badge +2

When setting up the REST service you use a swagger file that contains the host name, but how do you set the host name based on, e.g. an environment variable or a variable in your workflow? It seems like it would be a common requirement if you are hitting custom in-house API end-points and you have different hosts for your test vs production (that's our use-case). Are we stuck with having to have to manually create different swagger files and services for each environment? 


2 replies

Userlevel 2
Badge +10

Hi Chris-L,


 


It sounds like you want dynamic hostname in the Swagger file or have a K2 environment field that will handle it. I'm not quite sure if this is some thing that can be done in the product. According to the link below, the base url must have an actual host name, I suspect the K2 REST service will throw a validation message it's not an actual value.


https://swagger.io/docs/specification/2-0/api-host-and-base-path/


 

Userlevel 3
Badge +9

Yeah you need to do this, unless you could somehow have a dynamic json file server up a different host based upon the k2 server connecting to it, but that sounds very complicated and would need an endpoint that all of your K2 servers could see.


 


I automated this away by having some PowerShell to spit them out for me for each target environment.


 


Cheers

Reply