Best answer

Possible to add label if it doesn't already exist in Gmail?

  • 12 June 2021
  • 5 replies
  • 200 views

Hi there,

There doesn’t seem to be a “search for label” option in the Gmail connector. I want to add a label to a Gmail message, and if it doesn’t exist, create it.

 

I tried to just add the label but there’s no option to “create if it doesn’t exist” so the zap failed. Next I tried creating the label first, then applying it, but it bombs out if the label already exists. I’m processing a bunch of emails that come in with a pre-defined subject, and part of the subject needs to be used as the label.

 

Is there a way to do this, or a way to use the Filter or Path function to catch the zap if it fails and take an alternate course?

 

TIA.

icon

Best answer by SamB 12 August 2021, 17:36

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

Userlevel 7
Badge +14

Hi @Yempo Zaps 

Try instead using Gmail Rules to filter your emails and apply Labels: https://support.google.com/mail/answer/6579/create-rules-to-filter-your-emails?hl=en

Thanks, I looked at that. But the label name needs to be created on the fly by using a segment of the subject line. Gmail doesn’t have the tools to do that. I use Zapier formatting to determine the label name, but can’t apply it due to the problem above.

Userlevel 7
Badge +14

@Yempo Zaps 

NOTE: If you’re trying to dynamically map Labels in Zap steps, it will expect the internal Label ID, not the friendly Label Name.

Example:

 

[ADVANCED]

Gmail has an API which can be used to search/create Labels: https://developers.google.com/gmail/api/reference/rest/v1/users.labels/create

App APIs can be used in Zaps with the Webhooks step: https://zapier.com/apps/webhook/integrations#triggers-and-actions

Userlevel 2

Just a quick addendum to what @Troy Tessalone said.

In order to search the labels, you’ll need to use the user.labels /list command, here:
Method: users.labels.list  |  Gmail API  |  Google Developers

 

If you just want to try it once, the only thing you need to do is type the following in the userId field which should have a left bar that is red on it:

me

I think that the URL I put in above even does that for you, though!

 

Programmatically handling this in Zapier, though, is beyond me, as I find Power Automate a better playground to playing with that kind of data. Still, you’ll have a list that you can check against, and if it’s not there, then use Troy’s command to add the label. :-)

Good luck, @Yempo Zaps !!!

Userlevel 7
Badge +10

Just wanted to follow up here to add that while there isn’t a “Find Label” action for the Gmail integration (only a Create Label action currently), we do have an existing feature request for this capability to be added.

@Yempo Zaps, I’ve added your vote to that feature request to help us keep track of user interest in this. I don’t have an ETA on when it will be added but we’ll be sure to notify you by email once it is!


In the meantime, Troy and Eliot’s suggestions on using a Webhooks by Zapier action to connect to the Gmail API would definitely be a good workaround to try. :)