Why a redirection to a hard Kibana URL works but not when the URL is dynamically created

Hello,

I'm trying to generate connection urls to go from a home application to specific queries in our Kibana.

To do this I already asked the following question on the forum yesterday: previous question

I've moved on a bit since then but I'm in a situation I don't understand.

If I pass my url by writing it directly in a string the redirection is done to the right index and the right session.

But if I create the same string but dynamically to associate each id, then kibana redirects me to the base index without any data in the query.

Hard-coded URL in the code:

const URL_ROOT_KIBANA_DISCOVER_TEST = "http://HOST_NAME:5601/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-15M,to:now))&_a=(columns:!(_source),index:ab4ed2e0-fe84-11eb-8151-69b4ba83c682,interval:auto,query:(language:kuery,query:'FIELD_AGGREGATE_NAME:FIELD_VALUE%20and%20_id:" +'"ID_TO_RESEARCH"' + "'),sort:!(!('@timestamp',desc)))";

function createKibanaUrl(): string {
        //This method by hard-coding the url works well
        let testKibana = URL_ROOT_KIBANA_DISCOVER_TEST;
        return testKibana;
    }

The URL is assigned to the href of an anchor tag contained in a button and by pressing the button I am sent back to the right session.

const TEMPORARY_INDEX = "ab4ed2e0-fe84-11eb-8151-69b4ba83c682";
const URL_ROOT_KIBANA_DISCOVER = "http://HOST_NAME:5601/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:0),time:(from:now-";

const diffDays = (selectedDate: Date) => Math.ceil(Math.abs(new Date().getTime() - new Date(selectedDate).getTime()) / (1000 * 60 * 60 * 24));
const diffMonths = (selectedDate: Date) => new Date(selectedDate).getMonth() - new Date().getMonth() + 12 * (new Date(selectedDate).getFullYear() - new Date().getFullYear());
const diffYears = (selectedDate: Date) => new Date(selectedDate).getFullYear() - new Date().getFullYear();

function createKibanaUrl(timestamp: Date, idSession: string): string {
        let kibanaUrl: string = URL_ROOT_KIBANA_DISCOVER;
        const timeSlotInDays = diffDays(timestamp);
        const timeSlotInMonths = diffMonths(timestamp);
        const timeSlotInYears = diffYears(timestamp);
        if (timeSlotInDays <= 30) {
            kibanaUrl = kibanaUrl + timeSlotInDays.toString() + "d,to:now))";
        } else if ( timeSlotInDays > 30 && timeSlotInDays < 365) {
            kibanaUrl = kibanaUrl + timeSlotInMonths.toString() + "M,to:now))";
        } else if (timeSlotInDays >= 365) {
            kibanaUrl = kibanaUrl + timeSlotInYears.toString() + "y,to:now))";
        }
        kibanaUrl = kibanaUrl + "&_a=(columns:!(_source),index:" + TEMPORARY_INDEX + ",interval:auto,query:(language:kuery,query:'FIELD_AGGREGATE_NAME:" + "FIELD_VALUE" + "%20and%20_id:" + '"' + idSession + '"' + "'),sort:!(!('@timestamp',desc))"
        return kibanaUrl;
    }

With this method I am returned to the base page of my company's Kibana Discover application, the url I assigned is deleted and then replaced at the beginning of the kibana connection.
What can explain this problem please

Sorry for the inconvenience, I just realized that I had forgotten a parenthesis at the end of my dynamically generated url :man_facepalming: