# Mailbox Functions

The mailbox API allows us to have an internal message bus for our tests. The mailbox is a key value store in which each key can store an array of values. It acts as a Last in, first out (LIFO) stack, so the last message that was posted to the mailbox will be popped the first.

You can use the following functions to interact with the Mailbox.

#### POST

This function will add a new value to the specified key.

```javascript
//this function takes a string key and a value of any type as arguments
mailbox.post(key, value)

mailbox.post("key1", 33)
mailbox.post("key1", "Hello World")
mailbox.post("key1", {"Hello" : "World"})
```

#### POP

This function will pop the last data that was added to the key.

```javascript
//this function takes a string key as an argument
mailbox.pop(key)

mailbox.pop("key1")
mailbox.pop("key1")
```

{% code title="Response:" %}

```json
{ Hello: 'World' }
Hello World
```

{% endcode %}

#### COUNT

This function gives a count of the number of values with the current key.

```javascript
//this function takes a string key as an argument
mailbox.count(key)

//Example
mailbox.post("key1", 33)
mailbox.post("key1", "Hello World")

mailbox.count("key1")
```

{% code title="Response:" %}

```json
2
```

{% endcode %}

#### DUMP

This function dumps all the content inside the key instead of popping the values one by one.

It returns an array with all the values.

```javascript
//this function takes a string key as an argument
mailbox.dump(key)

//Example
mailbox.post("key1", 33)
mailbox.post("key1", "Hello World")

mailbox.dump("key1")
```

{% code title="Response:" %}

```json
[{ Hello: 'World' }, 'Hello World']
```

{% endcode %}

#### DELETE

This function deletes all the data for the mentioned key.

```javascript
//this function takes a string key as an argument
mailbox.delete(key)

mailbox.delete("key1")
```


---

# 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.iotify.io/additional-helpers/iotify-helpers/mailbox-functions.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.
