# How to pass URL parameters to a chat scenario

**URL:** <https://community.brightpattern.com/t/how-to-pass-url-parameters-to-a-chat-scenario/839>\
**Category:** API and Integrations\
**Created:** [May 25, 2023, 5:57pm UTC](https://community.brightpattern.com/t/how-to-pass-url-parameters-to-a-chat-scenario/839 "2023-05-25T17:57:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil.Austin](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@Neil.Austin](https://community.brightpattern.com/u/Neil.Austin)\
**Post date:** [May 25, 2023, 5:57pm UTC](https://community.brightpattern.com/t/how-to-pass-url-parameters-to-a-chat-scenario/839/1 "2023-05-25T17:57:47Z")

</div>

Hello everyone,

I frequently find myself returning to this particular use case and having to search through old code to locate it. To make it easier for me to find in the future, I will leave it here as a post.

The following JavaScript code, when placed somewhere above the chat snippet on the page, will extract URL parameters and store them in an array called “url\_params”:

```auto
<script language="JavaScript">
function getQueryString() {
  var result = {};
  var queryString = location.search.slice(1);
  var re = /([^&=]+)=([^&]*)/g;
  var m;
  
  while (m = re.exec(queryString)) {
    result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  }
  return result;
}

var url_params = getQueryString();
</script>

```

Instead of explicitly specifying the parameters in the chat snippet like this:  
(from here: [5.3:Tutorials-for-admins/Chat/PassJavascriptVariables - Bright Pattern Documentation](https://help.brightpattern.com/5.3:Tutorials-for-admins/Chat/PassJavascriptVariables))

```auto
parameters: {
variable_name: 'Value',
}

```

In the chat snippet, assign the previously created “url\_params” array to the parameters:

```auto
parameters: url_params

```

By doing this, the parameter array containing the URL variables will be sent as scenario invocation parameters, accessible as $(item.externalChatData.paramname).

---

<div class="post-metadata">

**Author:** ![rogerm](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rogerm](https://community.brightpattern.com/u/rogerm)\
**Post date:** [May 26, 2023, 7:33pm UTC](https://community.brightpattern.com/t/how-to-pass-url-parameters-to-a-chat-scenario/839/2 "2023-05-26T19:33:21Z")

</div>

Very useful, thank you.

---

<div class="post-metadata">

**Author:** ![Konsta\_Jaske](https://sea2.discourse-cdn.com/flex020/user_avatar/community.brightpattern.com/konsta_jaske/32/305_2.png) [@Konsta\_Jaske](https://community.brightpattern.com/u/Konsta_Jaske)\
**Post date:** [February 8, 2024, 9:05pm UTC](https://community.brightpattern.com/t/how-to-pass-url-parameters-to-a-chat-scenario/839/3 "2024-02-08T21:05:42Z")

</div>

Just what I was looking for, thank you!
