# How to set and access a list slot

**URL:** <https://forum.rasa.com/t/how-to-set-and-access-a-list-slot/36026>\
**Category:** Rasa Open Source\
**Created:** [October 19, 2020, 2:43am UTC](https://forum.rasa.com/t/how-to-set-and-access-a-list-slot/36026 "2020-10-19T02:43:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovanadionisio](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@giovanadionisio](https://forum.rasa.com/u/giovanadionisio)\
**Post date:** [October 19, 2020, 2:43am UTC](https://forum.rasa.com/t/how-to-set-and-access-a-list-slot/36026/1 "2020-10-19T02:43:04Z")

</div>

I’m creating a custom action that accesses an API that returns a list of fun facts. I am trying to save this return in a **list slot** , but I can’t access it.  
When I try to do this, I get the following error:

```auto
2020-10-19 01:02:50 ERROR rasa.core.processor - Encountered an exception while running action 'action_cat_facts'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
2020-10-19 01:02:50 DEBUG rasa.core.processor - Failed to execute custom action.
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/rasa/core/actions/action.py", line 551, in run
    json=json_body, method="post", timeout=DEFAULT_REQUEST_TIMEOUT
  File "/usr/local/lib/python3.7/site-packages/rasa/utils/endpoints.py", line 154, in request
    response.status, response.reason, await response.content.read()
rasa.utils.endpoints.ClientResponseError: 500, Internal Server Error, body='b'\n <h1>Internal Server Error</h1>\n <p>\n The server encountered an internal error and cannot complete\n your request.\n </p>\n''

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/rasa/core/processor.py", line 650, in _run_action
    events = await action.run(output_channel, nlg, tracker, self.domain)
  File "/usr/local/lib/python3.7/site-packages/rasa/core/actions/action.py", line 574, in run
    raise Exception("Failed to execute custom action.") from e
Exception: Failed to execute custom action.
2020-10-19 01:02:50 DEBUG rasa.core.processor - Action 'action_cat_facts' ended with events '[]'.

```

**domain.yml**

```auto
slots:
  fatos_sobre_gatos:
    type: list
actions:
- action_cat_facts   

```

**stories.md**

```auto
## fato_sobre_gato
* fatos_sobre_gatos
    - utter_fato_sobre_gatos
    - action_cat_facts

```

**action.py**

```auto
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet
import requests

from random import randint

class ActionCatFacts(Action):
    def name(self) -> Text:
        return "action_cat_facts"

    def run(self, dispatcher, tracker, domain):

        if len(tracker.get_slot("fatos_sobre_gatos")) == 0:
            req = requests.request('GET', "https://cat-fact.herokuapp.com/facts")
            lista = []
            for n in range(3):
                lista.append(req.json()["all"][n]["text"])
            
            fato = lista[randint(0, 2)]
            
            try:
                dispatcher.utter_message("{}".format(fato))
            except ValueError:
                dispatcher.utter_message(ValueError)
            return [SlotSet("fatos_sobre_gatos", lista)]
        else:
            fato = tracker.get_slot("fatos_sobre_gatos")[randint(0, 2)]
            try:
                dispatcher.utter_message("{}".format(fato))
            except ValueError:
                dispatcher.utter_message(ValueError)
            return []   

```

---

<div class="post-metadata">

**Author:** ![giovanadionisio](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@giovanadionisio](https://forum.rasa.com/u/giovanadionisio)\
**Post date:** [October 24, 2020, 5:06pm UTC](https://forum.rasa.com/t/how-to-set-and-access-a-list-slot/36026/2 "2020-10-24T17:06:40Z")

</div>

In the action file I was trying to get the len of a variable that had not yet been established, that is, a None variable. To fix this, I used the logical value of the slot.
