POST Url encoding: how do I encode portions of the URL?

With reference to the following documentation:

In it, you can copy a POST Url. I would like to add this url to a file, and then tokenise parts of it so that it can be re-used across multiple runs of a Jenkins pipeline.

Here is what I have at the moment:

    https://@@hostName@@:@@port@@/kibana/api/reporting/generate/printablePdf?jobParams=%28browserTimezone%3AEurope%2FDublin%2Clayout%3A%28dimensions%3A%28height%3A1120%2Cwidth%3A1914%29%2Cid%3Apreserve_layout%29%2CobjectType%3Adashboard%2CrelativeUrls%3A%21%28%27%2Fapp%2Fkibana%23%2Fdashboard%2Fi@@dashboardName@@%3F_g%3D%28filters%3A%21%21%28%29%2CrefreshInterval%3A%28pause%3A%21%21t%2Cvalue%3A0%29%2Ctime%3A%28from%3Anow-15m%2Cto%3Anow%29%29%26_a%3D%28description%3A%21%27Overview%2520of%2520system%2520metrics%21%27%2Cfilters%3A%21%21%28%29%2CfullScreenMode%3A%21%21f%2Coptions%3A%28darkTheme%3A%21%21f%29%2Cquery%3A%28language%3Akuery%2Cquery%3A%21%27%21%27%29%2CtimeRestore%3A%21%21f%2C

I have put @@ tokens around the hostName, port and dashboardName. I can then substitute those at runtime. I am having some trouble with the 'description' field, as there seems to be some (Rison?) formatting used:

description%3A%21%27Overview%2520of%2520system%2520metrics%21%27%

Is there any way to encode this?

The jobParams query parameter is first rison-encoded, then URI encoded. I'm not sure you've got the dashboard name portion correct... Do you mind pasting the full URL here so I can help?

I think in general what you'll need to do is something like this:

description%3A%21%27@@description@@%21%27

And in order for the description to be encoded properly, you'll have to first rison-encode it and then URI encode it (via encodeURIComponent). In practice, you should be able to just use encodeURIComponent twice:

encodeURIComponent(encodeURIComponent('Overview of system metrics'))
// results in "Overview%2520of%2520system%2520metrics"
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.