Unchanging string in items

Quick question I am struggling to find an answer for…

I am using openhab so get various info from my octoprint server.

An item looks like this:

Number OctoprintJobEstimatedPrintTime   "Estimated Print Time [%.0f s]" <time>  (gOctoprint)    {http="<[http://96.69.1.215/api/job?apikey=myApiKeyABCDEF123456:60000:JSONPATH($.job.estimatedPrintTime)]"}

There are quite a few of these and my API key sometimes changes when I have to reinstall stuff etc etc, whatever.

I’d like to create a “virtual” item that is simply a string containing the API key, the insert that string variable into the URL above, so when the key changes I only have to update it in one place.

Something like this:

String OctoprintApiKey "Octoprint API Key" (gOctoprint) {"myApiKeyABCDEF123456"}
Number OctoprintJobEstimatedPrintTime   "Estimated Print Time [%.0f s]" <time>  (gOctoprint)    {http="<[http://96.69.1.215/api/job?apikey=" + OctoprintApiKey + ":60000:JSONPATH($.job.estimatedPrintTime)]"}

Obviously, this doesn’t work else I wouldn’t be asking.

Can anyone help, or suggest a better way, please?

Cheers

You can use the http action instead in a rule
This way you could insert the API in the url

Also see Design Pattern: Encoding and Accessing Values in Rules