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

**URL:** <https://discuss.elastic.co/t/why-a-redirection-to-a-hard-kibana-url-works-but-not-when-the-url-is-dynamically-created/311215>\
**Category:** Kibana\
**Created:** [August 2, 2022, 12:12pm UTC](https://discuss.elastic.co/t/why-a-redirection-to-a-hard-kibana-url-works-but-not-when-the-url-is-dynamically-created/311215 "2022-08-02T12:12:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent92](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@Vincent92](https://discuss.elastic.co/u/Vincent92)\
**Post date:** [August 2, 2022, 12:12pm UTC](https://discuss.elastic.co/t/why-a-redirection-to-a-hard-kibana-url-works-but-not-when-the-url-is-dynamically-created/311215/1 "2022-08-02T12:12:58Z")

</div>

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](https://discuss.elastic.co/t/how-to-redirect-an-application-to-a-session-of-a-specific-index-on-kibana/311133)

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:

```auto
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.

```auto
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

---

<div class="post-metadata">

**Author:** ![Vincent92](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@Vincent92](https://discuss.elastic.co/u/Vincent92)\
**Post date:** [August 2, 2022, 1:53pm UTC](https://discuss.elastic.co/t/why-a-redirection-to-a-hard-kibana-url-works-but-not-when-the-url-is-dynamically-created/311215/2 "2022-08-02T13:53:07Z")

</div>

Sorry for the inconvenience, I just realized that I had forgotten a parenthesis at the end of my dynamically generated url 🤦‍♂️

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 30, 2022, 1:53pm UTC](https://discuss.elastic.co/t/why-a-redirection-to-a-hard-kibana-url-works-but-not-when-the-url-is-dynamically-created/311215/3 "2022-08-30T13:53:28Z")

</div>

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