Search code examples
apigoogle-apps-scriptgoogle-cloud-platformgmaildrive

Is it possible to create and name a folder on Google drive based on the contents of Gmail


As title, it is possible to do that through APIs? I have tried both Drive APIs and Gmail API, but it doesn’t seem to work out


Solution

  • Yes, it is possible!

    You need to make use of the Gmail API first to get the data wanted.

    For this, you can use the below request:

    GET https://gmail.googleapis.com/gmail/v1/users/USER_ID/messages/MESSAGE_ID
    

    Where USER_ID is the email address of the user for which you need to get the data from.

    Afterwards, you can do some data manipulation in order to get the exact part that is of interest to you and in order to create a folder using the Drive API, you can use the below request:

    POST https://www.googleapis.com/drive/v3/files
    

    With the following body:

    {
      "mimeType": "application/vnd.google-apps.folder"
    }
    

    Reference