# Share data between custom actions

**URL:** <https://forum.rasa.com/t/share-data-between-custom-actions/33133>\
**Category:** Rasa Open Source\
**Created:** [August 29, 2020, 1:10am UTC](https://forum.rasa.com/t/share-data-between-custom-actions/33133 "2020-08-29T01:10:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrepot33](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mrepot33/32/2091_2.png) [@mrepot33](https://forum.rasa.com/u/mrepot33)\
**Post date:** [August 29, 2020, 1:10am UTC](https://forum.rasa.com/t/share-data-between-custom-actions/33133/1 "2020-08-29T01:10:55Z")

</div>

Hi! I’m building a bot where in the first user interaction I make a third party API request to get product data. That’s done in one specific action.

But then I’d like to use the same data in another actions but I don’t know how to share or where to save the data collected from the first one.

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [August 31, 2020, 12:48pm UTC](https://forum.rasa.com/t/share-data-between-custom-actions/33133/2 "2020-08-31T12:48:53Z")

</div>

Hi @mrepot33. You can set the details extracted by one [action as slots](https://rasa.com/docs/rasa/core/slots/#slots-set-by-actions). Then in your other action, you can extract the values of those slots using the method `tracker.get_slot("slot_name")`

---

<div class="post-metadata">

**Author:** ![mrepot33](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/mrepot33/32/2091_2.png) [@mrepot33](https://forum.rasa.com/u/mrepot33)\
**Post date:** [August 31, 2020, 4:59pm UTC](https://forum.rasa.com/t/share-data-between-custom-actions/33133/3 "2020-08-31T16:59:12Z")

</div>

Hi @Juste, I’ve already tried that but the slot was then empty. This is my code.

“data” is a big json containing a lot of data from an item that I’d like to share between actions, avoiding making third party API requests each time. Sharing this data across actions would be the ideal solution.

A workaround solution would be to use a cache (redis in this case) in order to store the data there, using the “itemid” as the key. Then in the other action I could retrieve the data by using that id. The problem is that “itemid” is then empty.

```
class ActionA(Action):
def name(self) -> Text:
    return "actiona"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    
    price = tracker.get_slot('price')      
    itemid = tracker.get_slot('itemid')
    data = rcache.get(itemid)
    if not data:
        data = get_item_data(itemid)
        rcache.mset({itemid: data})
    
    ....

    return [SlotSet('offer', offer)]

```

class ActionB(Action):

```
def name(self) -> Text:
    return "actionb"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    
    
    itemid = tracker.get_slot('itemid') #empty value
    ...
```

---

<div class="post-metadata">

**Author:** ![Juste](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/juste/32/15_2.png) [@Juste](https://forum.rasa.com/u/Juste)\
**Post date:** [September 1, 2020, 12:12pm UTC](https://forum.rasa.com/t/share-data-between-custom-actions/33133/4 "2020-09-01T12:12:58Z")

</div>

Using the method `tracker.get_slot()` you are extracting the values from tracker. That’s why, for this to work, your custom action `actiona` should return an event `SlotSet` for the `itemid` slot as well (just like you are doing it for the slot `offer`). You can do it by modifying the last line of `actiona` as follows:

```auto
return [SlotSet('offer', offer), SlotSet('itemid', data)]

```

Once you do that, the `itemid` should be saved as slot in the tracker as well and this slot then should be available for your `actionb`.
