Skip to main content
Solved

Create an RPA workflow to log into a Gmail mailbox and delete all its messages using API

  • October 22, 2024
  • 3 replies
  • 64 views

Forum|alt.badge.img+1

Hi All,

 

Please help me to create a Bot to log into a Gmail mailbox and delete all its messages using Gmail API.

 

Thanks,

Shivansh

Best answer by Padmakumar

Hi ​@Shivansh15 ,

 

In a nutshell, the logic will be as shown below.

 

  1. Set up Google Cloud Project and Enable Gmail API:

    • Create a project in Google Cloud Console.
    • Enable the Gmail API for that project.
    • Create OAuth 2.0 credentials (Client ID and Client Secret) for a desktop or web application.
  2. Authenticate and Obtain Access Token:

    • Use OAuth 2.0 to authenticate the user and obtain an access token with Gmail scopes (

      https://www.googleapis.com/auth/gmail.modify

       or 

      https://www.googleapis.com/auth/gmail.delete

      ).
  3. Use Gmail API to List and Delete Messages:

    • Use the API endpoint 

      users.messages.list to get message IDs.

    • Use 

      users.messages.delete or 

      users.messages.batchDelete to delete messages.

  4. Automate this Using A360 Bot:

    • Use HTTP Request actions to call Gmail API endpoints.
    • Handle OAuth 2.0 authentication flow (can be complex; consider using a script or external tool to get tokens).
    • Loop through messages and delete them.

3 replies

Forum|alt.badge.img+17
  • Most Valuable Pathfinder
  • October 22, 2024

@Shivansh15  How about posting what you have tried on your own? We’d then be happy to help.


CaptainPathfinder
Forum|alt.badge.img+3

That’s an interesting question, Shivansh15 !

I think the following community members may be able to help 

@ChanduMohammad 

@Zaid Chougle 

@Tamil Arasu10 

@Paul Hawkins 

@Padmakumar 


Padmakumar
Premier Pathfinder | Tier 7
Forum|alt.badge.img+15
  • Premier Pathfinder | Tier 7
  • Answer
  • July 16, 2025

Hi ​@Shivansh15 ,

 

In a nutshell, the logic will be as shown below.

 

  1. Set up Google Cloud Project and Enable Gmail API:

    • Create a project in Google Cloud Console.
    • Enable the Gmail API for that project.
    • Create OAuth 2.0 credentials (Client ID and Client Secret) for a desktop or web application.
  2. Authenticate and Obtain Access Token:

    • Use OAuth 2.0 to authenticate the user and obtain an access token with Gmail scopes (

      https://www.googleapis.com/auth/gmail.modify

       or 

      https://www.googleapis.com/auth/gmail.delete

      ).
  3. Use Gmail API to List and Delete Messages:

    • Use the API endpoint 

      users.messages.list to get message IDs.

    • Use 

      users.messages.delete or 

      users.messages.batchDelete to delete messages.

  4. Automate this Using A360 Bot:

    • Use HTTP Request actions to call Gmail API endpoints.
    • Handle OAuth 2.0 authentication flow (can be complex; consider using a script or external tool to get tokens).
    • Loop through messages and delete them.