Dynamic variable in HTTP Binding

Hey guys,

I am trying to get data from the API of my local Bus service provider.
Fetching the next departures was simple and is working just fine. Additionally I would like to fetch the location of the next bus. For this I need the Id of said Bus which I can get from another Endpoint.

Is there any way to dynamically inject that ID into the thing for the other endpoint? Something like saving it to an item and using the item value in the other thing maybe?

Regards Felix

I suppos, you could use commandTransformation to run a script that includes the Bus Id (stored in an Item or temporary variable) in the command sent to the API. See the documention.

My problem is, that I need to put the parameter in the URL and not in the body. As far as I know command transformation is only applied to the body of the request.

Then you may have to resort to direct HTTP calls in a script/rule. Alternatively (also in a rule), you could create/destroy the channels dynamically.
Someone else may come up with a simpler solution, but that’s what I can think of.

It seems that it might be possible using %2$: URL Formatting

Hmm yes I thought about it as well. But that value probably is only abailable in write operations if i am not mistaken. And if I use tje write call how would i get the response?

You could dynamically change the channel configuration whenever the bus id changed, using a rule.

Example in JRuby:

# Item that contains the bus id = BusID
# Item that contains the bus location = BusLocation
rule "Update Bus Location URL" do
  changed BusID
  run do |event|
    next unless event.state?

    state_extension = "?busId=#{event.state}"
    # Prevent disabling/enabling the Thing when the config is already updated
    next if BusLocation.channel.configuration["stateExtension"] == state_extension

    BusLocation.channel.configuration["stateExtension"] = state_extension

    # refresh config