# cookie

Use cookies to set data in the user's browser that can persist between sessions. The `cookie` action allows for setting values into a cookie, and you can use a JavaScript function to retrieve the data back later.

Cookie values can also be retrieved in your FileMaker scripts. They are stored as a JSON object in the **$$BF\_State** variable: `JSONGetElement ( $$BF_State ; "params.handshake.headers.cookie" )`

## Options

|     Options Key |        Type        | Description                                                                                    |
| --------------: | :----------------: | ---------------------------------------------------------------------------------------------- |
|        `action` |      *string*      | Options: `set` and `remove` The cookie action to perform. For `get` support see examples below |
| `daysOrOptions` | *number or object* | If number, the number of days before the cookie expires, If object see additional notes        |
|          `name` |      *string*      | Cookie name                                                                                    |
|         `value` |      *string*      | Cookie value                                                                                   |

To remove a cookie simply set the `daysOrOptions` value to `0`

## **Examples**

```yaml
// action  object for 'cookie'
[
  {
    "action": "cookie",
    "options": {
      "action": "set",     // or get or remove
      "daysOrOptions": 1,
      "name": "MyCookieName",
      "value": "my cookie value"
    }
  }
]
```

```javascript
// As JS function 
Vue.cookie.set('cookieName', 'some info here', 7);
Vue.cookie.getJSON('cookieName'); // returns JSON obj of cookie data

// Setting a cookie from a click within a HTML 
... @click="Vue.cookie.set('myCookieName', 4)" ...
```

There is no built-in custom function at this time. If you want to set a cookie from a FileMaker script, use the BF\_SetAction\_Function action with the functions above.

{% hint style="warning" %}
Cookies that you set in a browser are will persist for every page in your site (until they expire) and are sent with every hook script back to your FileMaker server. Be careful not to store too much data in cookies as this can impact your site's performance.

For more on reducing the payload that is sent to your FileMaker server, see [this page](/reference/hooksoverview/env_vars.md).
{% endhint %}

## Additional Reference:

This action is based on the following Vue modules:

{% embed url="<https://github.com/BlueBayTravel/vue-js-cookie>" %}

{% embed url="<https://github.com/js-cookie/js-cookie/>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.klai.studio/reference/actions-processor/actions_overview/cookie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
