# Gooogle Drive Api and Slot issue

**URL:** <https://forum.rasa.com/t/gooogle-drive-api-and-slot-issue/25762>\
**Category:** Rasa Open Source\
**Created:** [March 6, 2020, 7:20pm UTC](https://forum.rasa.com/t/gooogle-drive-api-and-slot-issue/25762 "2020-03-06T19:20:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![athenasaurav](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/athenasaurav/32/8139_2.png) [@athenasaurav](https://forum.rasa.com/u/athenasaurav)\
**Post date:** [March 6, 2020, 7:20pm UTC](https://forum.rasa.com/t/gooogle-drive-api-and-slot-issue/25762/1 "2020-03-06T19:20:43Z")

</div>

Hello Everyone,

I ran into a strange problem while doing this activity already posted here : [Rasa Google Drive API](http://forum.rasa.com/t/rasa-google-drive-api/25743).

I solved this problem with following code :

class ActionQuestion(Action): # def name(self) -\> Text: return “action\_question”

```
def run(self, dispatcher: CollectingDispatcher,

        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    import pickle
    import os.path
    from googleapiclient.discovery import build
    from google_auth_oauthlib.flow import InstalledAppFlow
    from google.auth.transport.requests import Request
    import logging

    logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)
    # If modifying these scopes, delete the file token.pickle.
    SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']

    creds = None
        # The file token.pickle stores the user's access and refresh tokens, and is
        # created automatically when the authorization flow completes for the first
        # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
        # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
            # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('drive', 'v3', credentials=creds)
        # Call the Drive v3 API

    page_token = None
    while True:
        response = service.files().list(q="name='Getting Started'",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()
        for file in response.get('files', []):
            # Process change
            dispatcher.utter_message('Found file: %s please visit the link https://drive.google.com/open?id=%s' % (file.get('name'), file.get('id')))
            dispatcher.utter_message(type(question))
        page_token = response.get('nextPageToken', None)
        if page_token is None:
            break
    return []

```

My issue is when instead of directly passing the name of file in these line:

```
        response = service.files().list(q="name='Getting Started'",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()

```

i use the tracker.get\_slot method to pass the name of file like this:

```
    question = tracker.get_slot("document")
    response = service.files().list(q="name=question",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()

```

i get the following http error:

googleapiclient.errors.HttpError: \<HttpError 400 when requesting [https://www.googleapis.com/drive/v3/files?q=name+%3D+question&spaces=drive&fields=nextPageToken%2C+files(id%2C+name)&alt=json](https://www.googleapis.com/drive/v3/files?q=name+%3D+question&spaces=drive&fields=nextPageToken%2C+files%28id%2C+name%29&alt=json) returned “Invalid Value”\>

When running the direct values i get the following http resquest and return correct value:

googleapiclient.discovery - URL being requested: GET [https://www.googleapis.com/drive/v3/files?q=name+%3D+'getting+started'&spaces=drive&fields=nextPageToken%2C+files(id%2C+name)&alt=json](https://www.googleapis.com/drive/v3/files?q=name+%3D+%27getting+started%27&spaces=drive&fields=nextPageToken%2C+files%28id%2C+name%29&alt=json)

How to pass this slot in the request url correctly?

---

<div class="post-metadata">

**Author:** ![athenasaurav](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/athenasaurav/32/8139_2.png) [@athenasaurav](https://forum.rasa.com/u/athenasaurav)\
**Post date:** [March 6, 2020, 8:16pm UTC](https://forum.rasa.com/t/gooogle-drive-api-and-slot-issue/25762/2 "2020-03-06T20:16:00Z")

</div>

solved

```auto
        response = service.files().list(q='(name contains \'{0}\')'.format(a),
                                          spaces='drive',
                                          fields='nextPageToken, files(id, name)',
                                          pageToken=page_token).execute()

```
