Search code examples
google-apps-scriptgmail

Call Google Apps Script API with GmailApp function from Postman [without using AuthO2]


I am trying to access the Google Apps Script Gmail service with Postman. Here is my Google Apps Script Code, with a straightforward sendMail function:

function sendMail() {
  GmailApp.sendEmail('[email protected]','from inTracck','Test for new API source')
}

As you may see, it's a code to send a simple email. After deploying my project in Google Apps Script, I've got a Web App address to use on my postman:

Web App Address:
https://script.google.com/macros/s/.../exec

I put it all on my Postman, here is how I use it: Google Apps Script API in Postman

Now, the issue is that when I send the API, it doesn't work. I know that I might have to fill out the body section, but since I'm not very technical, I didn't know how to fill that to make the API works and send an email from my Postman.


Solution

  • You need a doGet() function to return data:

    function doGet(){
      sendMail();// call send email function
      return ContentService.createTextOutput('Email Sent!')
    }
    

    You should publish it with these configurations:

    • Execute as "Me"
    • Access:"Anyone"

    Note: Republishing changes the URL. Make sure to use the newly published URL in Postman.